-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSenha.java
More file actions
68 lines (49 loc) · 1.81 KB
/
Senha.java
File metadata and controls
68 lines (49 loc) · 1.81 KB
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
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
public class Senha {
private final String[] numeros = {"1","2","3","4","5","6","7","8","9","0"};
private final String[] caracMin = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
int tam, op;
String senha;
public Senha(int op, int tam){
if(tam < 8){
throw new RuntimeException("Informe um tamanho acima de 8 caracteres");
}
if (op > 2 || op < 1){
throw new RuntimeException("Opcao Invalida!!");
} else{
this.tam = tam;
this.op = op;
}
}
// Método usado para gerar o random do indice de cada caractere de acordo com o tamanho desejado
public String geradorSenha(int tam, int op, int qtd){
Random random = new Random();
int i,j, indice;
StringBuilder senha = new StringBuilder();
if (op == 1 ){
for(i = 0; i < qtd; i++){
for (j = 0 ; j < tam; j++){
indice = random.nextInt(numeros.length);
senha.append(numeros[indice]);
}
senha.append("\n");
}
} else if (op == 2) {
for (i = 0; i < qtd; i++){
for(j = 0; j < tam; j++){
indice = random.nextInt(caracMin.length);
senha.append(caracMin[indice]);
}
senha.append("\n");
}
}
return senha.toString();
}
public void salvaSenha(String resp, FileWriter escritor) throws IOException {
escritor.write(resp);
escritor.write("\n");
escritor.close();
}
}