-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
93 lines (79 loc) · 3.01 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Microsoft.Win32;
using System;
using System.Reflection;
using System.Windows;
namespace GSenha
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Version Versao = Assembly.GetExecutingAssembly().GetName().Version;
statusbaritemVersao.Content = String.Format("Versão {0}.{1}.{2} Revisão {3}", Versao.Major, Versao.Minor, Versao.Build, Versao.Revision);
}
private void ButtonGerar_Click(object sender, RoutedEventArgs e)
{
try
{
Random random;
String senhaGerada = String.Empty;
String caracteres = String.Empty;
String maiusculos = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String minusculos = "abcdefghijklmnopqrstuvwxyz";
String numeros = "1234567890";
String especiais = "!@#$%&_.";
if (checkboxMaiusculos.IsChecked == true)
{
caracteres += maiusculos;
}
if (checkboxMinusculos.IsChecked == true)
{
caracteres += minusculos;
}
if (checkboxNumeros.IsChecked == true)
{
caracteres += numeros;
}
if (checkboxEspeciais.IsChecked == true)
{
caracteres += especiais;
}
textboxSenhasGeradas.Text = String.Empty;
for (int i = 0; i < Convert.ToInt32(textboxNumeroDeSenhas.Text); i++)
{
for (int j = 0; j < Convert.ToInt32(textboxNumeroDeCaracteres.Text); j++)
{
random = new Random(DateTime.Now.Millisecond);
System.Threading.Thread.Sleep(1);
senhaGerada += caracteres[random.Next(0, caracteres.Length)].ToString();
}
textboxSenhasGeradas.Text += senhaGerada + Environment.NewLine;
senhaGerada = String.Empty;
}
this.buttonSalvar.IsEnabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void ButtonSalvar_Click(object sender, RoutedEventArgs e)
{
FileDialog pasta = new SaveFileDialog();
var resultado = pasta.ShowDialog();
if (resultado == true)
{
try
{
System.IO.File.WriteAllText(pasta.FileName.ToString() + ".txt", textboxSenhasGeradas.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
MessageBox.Show("Arquivo salvo!");
}
}
}
}