-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
98 lines (83 loc) · 2.95 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
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GeradorDeSenhas
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
static readonly string SenhaLetras = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static readonly string SenhaNumeros = "1234567890";
static readonly string SenhaEspecial = "!@#$%&*()_-+=;:,.{}`^~";
public bool UsarNumeros = true;
public bool UsarCaracteresEspeciais = true;
public int Tamanho = 10;
public MainWindow(){
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e){
tbTamanho.Text = Tamanho.ToString();
}
public string ObterSenha(int tamanho){
if (tamanho <= 0)
tamanho = 10;
string senha = string.Empty;
Random random = new();
string TempCaracteres;
for (int i = 0; i < tamanho; i++){
TempCaracteres = SenhaLetras;
if(UsarNumeros)
TempCaracteres += SenhaNumeros;
if(UsarCaracteresEspeciais)
TempCaracteres += SenhaEspecial;
int letra = random.Next(0, TempCaracteres.Length);
senha += TempCaracteres[letra];
}
return senha;
}
private void btnGerarSenha_Click(object sender, RoutedEventArgs e){
tbSenha.Text = "";
tbSenha.Text = ObterSenha(Tamanho);
btnCopiar.IsEnabled = true;
btnCopiar.Visibility = Visibility.Visible;
}
private void btnFecharApp_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
}
private void tbtnUsarNumeros_Click(object sender, RoutedEventArgs e){
UsarNumeros = !UsarNumeros;
}
private void tbtnUsarCharEspecial_Click(object sender, RoutedEventArgs e){
UsarCaracteresEspeciais = !UsarCaracteresEspeciais;
}
private void btnCopiar_Click(object sender, RoutedEventArgs e){
if (!string.IsNullOrWhiteSpace(tbSenha.Text)){
Clipboard.SetText(tbSenha.Text);
}
}
private void tbTamanho_TextChanged(object sender, TextChangedEventArgs e){
if (string.IsNullOrWhiteSpace(tbTamanho.Text)){
Tamanho = 10;
tbTamanho.Text = Tamanho.ToString();
}
int.TryParse(tbTamanho.Text, out Tamanho);
}
}
}