-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordApp.java
More file actions
60 lines (44 loc) · 3.05 KB
/
Copy pathPasswordApp.java
File metadata and controls
60 lines (44 loc) · 3.05 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
import java.util.Scanner; // Import Scanner class for reading user input
public class PasswordApp { // Main application class
public static void main(String[] args) { // Main method, entry point of the program
Scanner input = new Scanner(System.in); // Create a Scanner object to read input from the keyboard
System.out.println("How many times would you like to run the application?"); // Prompt user for number of runs
int runs = input.nextInt(); // Read integer input for number of runs
input.nextLine(); // Clear the newline character left in the input buffer
String[] allPasswords = new String[runs]; // Create an array to store all generated passwords
for (int i = 0; i < runs; i++) { // Loop to run the application the number of times specified
System.out.println("Run #" + (i + 1)); // Display current run number
// Get the user's forename and surname
System.out.println("Enter forename and surname (lowercase, e.g., 'daniel murphy'):");
String name = input.nextLine(); // Read the full line (forename and surname)
// Get the value of n (3, 4, or 5) with input validation
int n = 0; // Initialize n
while (n != 3 && n != 4 && n != 5) { // Keep looping until n is valid
System.out.println("Enter a number (3, 4, or 5):"); // Prompt for n
n = input.nextInt(); // Read integer input for n
input.nextLine(); // Clear the newline character left in the input buffer
}
// Get the special character to replace the space
System.out.println("Enter a special character (e.g., @, #, $, %, &, *):");
String specialInput = input.nextLine(); // Read the line as a string
char specialChar = specialInput.charAt(0); // Get the first character from the input string
// Create a PasswordGenerator object using the provided inputs
PasswordGenerator pg = new PasswordGenerator(name, n, specialChar);
// Compute the password by applying all processing steps
pg.computePassword();
// Retrieve the final generated password
String finalPassword = pg.getFinalPassword();
// Display the generated password to the user
System.out.println("Generated Password: " + finalPassword);
// Store the password in the array for later strength evaluation
allPasswords[i] = finalPassword;
}
// Create a dummy PasswordGenerator object just to call the evaluatePasswordStrength method
PasswordGenerator checker = new PasswordGenerator("", 3, '*'); // Empty values because we only need the method
// Display the password strength evaluation results
System.out.println("\nPassword Strength Results:");
checker.evaluatePasswordStrength(allPasswords); // Call method to evaluate and display strength of each password
// Indicate that the application has finished
System.out.println("Application finished.");
}
}