User Story
As a user, I want to be able to check the security of my password by running it through a password strength checker program. The program will take my password as input and will analyze it based on certain criteria, such as whether it contains upper and lower case letters, numbers, and special characters. The program will then calculate a score for my password based on these criteria and will output a message indicating the strength of my password. If my password is weak, the program will advise me to choose a stronger password, and if my password is strong, the program will confirm that my password is secure.
Create a Program which evaluates the secureness of a password. Create a variable with the name passwordsecurescore which will be max 10 points.
If your password has Alpha then 1 point
If your password has Lower Char then 2 point
If your password has Upper Char then 2 point
If your password has numeric Char then 2 point
If your password has Special Char then 3 point
When your password has less than 5 points, it's a Bad Password
When your password has less than 7 points, it's a Normal Password
Else your password is Best password
Code
String password ='ATaT45443123@@';
Boolean hasAlpha=false;
Boolean haslower=false;
Boolean hasUpper=false;
Boolean hasspecial=false;
Boolean hasnumeric=false;
Integer passwordSecureScore=0;
for(Integer i=0; i<=password.length()-1; i++){
if(password.substring(i,i+1).isAlpha()){
hasAlpha=true;
}
if(password.substring(i,i+1).isNumeric()){
hasAlpha=true;
}
if(password.substring(i,i+1).equals(password.substring(i,i+1).toUpperCase())){
haslower=true;
}
else{
haslower=false;
}
if(password.substring(i,i+1).equals(password.substring(i,i+1).toLowerCase())){
hasUpper=true;
}
else{
hasUpper=false;
}
if(!password.substring(i,i+1).isAlpha() && !password.substring(i,i+1).isnumeric()){
hasspecial=true;
}
if(!password.substring(i,i+1).isnumeric()){
hasnumeric=true;
}
}
if(hasAlpha){
passwordSecureScore+=1;
}
if(haslower){
passwordSecureScore+=2;
}
if(hasUpper){
passwordSecureScore+=2;
}
if(hasnumeric){
passwordSecureScore+=2;
}
if(hasspecial){
passwordSecureScore+=3;
}
if(passwordsecurescore<5){
System.debug('Bad Password');
}
else if(passwordsecurescore<7){
System.debug('Normal Password');
}
else{
System.debug('Best Password');
}