import java.util.
Scanner;
public class PasswordGenerator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Generate your password");
String password = scanner.nextLine();
if (isValidPassword(password)) {
System.out.println("The generated password " + password + " is valid
and has " + countLowerCase(password) + " lowercase alphabet " +
countUpperCase(password) + " uppercase alphabet " +
countSpecialChar(password) + " special character " +
countDigits(password) + " digit");
} else {
System.out.println(password + " is an invalid password");
}
scanner.close();
}
public static boolean isValidPassword(String password) {
if (password.length() < 6 || password.length() > 12) {
return false;
}
boolean hasLowerCase = false;
boolean hasUpperCase = false;
boolean hasSpecialChar = false;
for (char c : password.toCharArray()) {
if (Character.isLowerCase(c)) {
hasLowerCase = true;
} else if (Character.isUpperCase(c)) {
hasUpperCase = true;
} else if (c >= Integer.parseInt("33") && c <= Integer.parseInt("47")
|| c >= Integer.parseInt("58") && c <= Integer.parseInt("62")) {
hasSpecialChar = true;
} else if (!Character.isDigit(c) && !Character.isLetter(c)) {
return false; // Invalid character
}
}
return hasLowerCase && hasUpperCase && hasSpecialChar;
}
public static int countLowerCase(String password) {
int count = 0;
for (char c : password.toCharArray()) {
if (Character.isLowerCase(c)) {
count++;
}
}
return count;
}
public static int countUpperCase(String password) {
int count = 0;
for (char c : password.toCharArray()) {
if (Character.isUpperCase(c)) {
count++;
}
}
return count;
}
public static int countSpecialChar(String password) {
int count = 0;
for (char c : password.toCharArray()) {
if (c == '@' || c == '$' || c == '*' || c == '#') {
count++;
}
}
return count;
}
public static int countDigits(String password) {
int count = 0;
for (char c : password.toCharArray()) {
if (Character.isDigit(c)) {
count++;
}
}
return count;
}
}