-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassWordGenerator.java
More file actions
65 lines (56 loc) · 2.12 KB
/
PassWordGenerator.java
File metadata and controls
65 lines (56 loc) · 2.12 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
import java.security.SecureRandom;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
public class PassWordGenerator {
private static final Scanner sc = new Scanner(System.in);
private static String website;
private static String username;
private static int length;
private static String password; // guarda a password gerada
public static void main(String[] args) {
receiveParameters();
passwordLength();
createPassword();
printPassword();
PasswordSaver.savePassword(website, username, password);
while(generateAnother()){
createPassword();
printPassword();
PasswordSaver.savePassword(website, username, password);
}
sc.close();
System.out.println("Programa terminado.");
}
public static void receiveParameters(){
System.out.println("Digite o endereço do website");
website = sc.nextLine();
System.out.println("Indique o nome de utilizador/email");
username = sc.nextLine();
}
public static void passwordLength(){
System.out.println("Indique o tamanho desejado da password entre 8 e 16 carateres");
length = sc.nextInt();
if(length < 8 || length > 16){
System.out.println("O tamanho da palavra passe deve estar entre 8 e 16");
sc.nextLine(); // limpar buffer do scanner
passwordLength();
}
}
public static void createPassword(){
password = Password.generateRandomPassword(length);
}
public static void printPassword(){
System.out.println("Resumo:");
System.out.println("Website: " + website);
System.out.println("Username: " + username);
System.out.println("Password: " + password);
}
public static boolean generateAnother(){
System.out.println("Deseja gerar outra palavra passe para esta conta? (sim/não)");
sc.nextLine(); // consumir o resto da linha anterior
String resposta = sc.nextLine().trim().toLowerCase();
return resposta.equals("sim");
}
}