CS111-Group Project Report Form (4)
CS111-Group Project Report Form (4)
By Group (G):
Supervised By
Date of signature
For instructor:
1
CLO Assigned marks Awarded marks
2.2 2
3.1 3
4.1 1
4.2 1
Total 7
import java.util.Scanner;
d
o
{
System.out.println("\nTo generate passwords, please enter 1.");
System.out.println("To check the strength of your password, please enter
2.");
System.out.println("To generate passwords and check their strengths,
please enter 3.");
2
System.out.println("To exit the program, please enter 0.");
System.out.print("Enter your choice: ");
while (!input.hasNextInt()) {
System.out.println("Invalid input. Please enter a valid number.");
input.next();
}
choice = input.nextInt();
switch (choice)
{ case 1:
System.out.print("Enter the password
length: "); int length1 = input.nextInt();
if (length1 > 0) {
case 2:
System.out.print("Enter your
password: "); String password =
input.next(); int score =
checkStrength(password);
printStrengthMessage(score); break;
case 3:
3
System.out.print("Enter the password
length: "); int length2 = input.nextInt();
if (length2 > 0) {
String[] passwords = generatePasswords(length2);
printPasswordsWithStrength(passwords);
} else {
System.out.println("Password length should be a positive integer.");
}
break;
case 0:
System.out.println("Exiting the program. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
} while (choice != 0);
input.close();
}
4
StringBuilder password = new
StringBuilder(); for (int j = 0; j < length; j+
+) {
int randomIndex = (int) (Math.random() * characters.length());
password.append(characters.charAt(randomIndex));
}
passwords[i] = password.toString();
}
return passwords;
}
5
if (password.matches(".*[A-Z].*")) score++; // Uppercase
letter if (password.matches(".*[a-z].*")) score++; //
Lowercase letter if (password.matches(".*\\d.*")) score+
+; // Number
if (password.matches(".*[!@#$%^&*()].*")) score++; // Special
character if (password.length() >= 8) score++; // Length >= 8
return score;
}
case 3:
System.out.println("This is a medium password, try making it
better."); break; case 2: case 1:
System.out.println("This is a weak password, you should find a new
one!"); break; default:
System.out.println("This password has no strength.");
break;
}
}
6
System.out.println("This is a very good
password!"); break; case 4:
System.out.println("This is a good password, but you can still do
better."); break; case 3:
System.out.println("This is a medium password, try making it
better."); break; case 2: case 1:
System.out.println("This is a weak password, you should find a new
one!"); break; default:
System.out.println("This password has no strength.");
break;
}
}
}
7
The outputs screenshots as copied from NetBeans:
Welcome to our password services project To generate passwords, please enter 1.
To check the strength of your password, please enter 2. To generate passwords and
check their strengths, please enter 3. To exit the program, please enter 0. Enter
your choice: 1
Enter the password length: 8 Here are a few options: 73X0r7AE WVEuPlex
UBOEA^0R To generate passwords, please enter 1. To check the strength of your
password, please enter 2. To generate passwords and check their strengths, please
enter 3. To exit the program, please enter 0. Enter your choice: 2 Enter your
password: 8 This is a weak password, you should find a new one! To generate
passwords, please enter 1. To check the strength of your password, please enter 2.
To generate passwords and check their strengths, please enter 3. To exit the
program, please enter 0. Enter your choice: 3 Enter the password length: 8 Here
are a few options: 5Z$tJSxg This is a very good password! sPpzkVKG This is a
medium password, try making it better. ctbBiFZ@ This is a good password, but
you can still do better. To generate passwords, please enter 1. To check the strength
of your password, please enter 2. To generate passwords and check their strengths,
please enter 3. To exit the program, please enter 0. Enter your choice: 0 Exiting the
program. Goodbye! BUILD SUCCESSFUL (total time: 55 seconds)