Write a program to accept a string and check if it makes a strong password.
(A strong password should have at least 8 characters, one Upper case character, one lowercase character, a digit and one special character).
Sample Input:
Senior@Lab94
Sample Output
Strong password
(USING BLUE J). No spam or report..
Answers & Comments
senior@lab94 should be the answer
Answer:
_______________________________________
public class StrongPasswordChecker {
public static void main(String[] args) {
// Accept the string from the user
Scanner input = new Scanner(System.in);
System.out.print("Enter your password: ");
String password = input.nextLine();
// Check if the password meets the criteria
boolean isStrong = isStrongPassword(password);
// Display the result
// Mark As Brainliest
if (isStrong) {
System.out.println("Strong password");
} else {
System.out.println("Weak password");
}
}
private static boolean isStrongPassword(String password) {
boolean hasUpperCase = false;
boolean hasLowerCase = false;
boolean hasDigit = false;
boolean hasSpecialChar = false;
if (password.length() < 8) {
return false;
}
for (int i = 0; i < password.length(); i++) {
char ch = password.charAt(i);
if (Character.isUpperCase(ch)) {
hasUpperCase = true;
} else if (Character.isLowerCase(ch)) {
hasLowerCase = true;
} else if (Character.isDigit(ch)) {
hasDigit = true;
} else {
hasSpecialChar = true;
}
}
return hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar;
}
}
_________________________________
Consider Marking as Brainliest
Happy Learning,
BrainOfficial