To validate strength of a password using regular expression in R
Load the password
If the password is less than 8 characters then declare the password as weak
If the password is greater than 8 characters and contains one upper case letter or one lower case letter and contains only one digit then declare the password as Medium
If the password is greater than 8 characters and contains more than one upper case letter or more than one lower case letter and contains more than one digit then declare the password as Strong
pw=readline(prompt = “Enter the password : “)
if (nchar(pw)<8) { cat(“Password Strength is weak\n”) }else if((nchar(pw)>8)&((length(unlist(regmatches(pw,gregexpr(“[A-Z]”,pw))))==1)|
(length(unlist(regmatches(pw,gregexpr(“[a-z]”,pw))))==1))&
(length(unlist(regmatches(pw,gregexpr(“[[:digit:]]”,pw))))==1))
{
cat(“Password strength is medium\n”)
}else if((nchar(pw)>8)&((length(unlist(regmatches(pw,gregexpr(“[A-Z]”,pw))))>1)|
(length(unlist(regmatches(pw,gregexpr(“[a-z]”,pw))))>1))&
(length(unlist(regmatches(pw,gregexpr(“[[:digit:]]”,pw))))>1)&
(length(unlist(regmatches(pw,gregexpr(“[~!@#$%^&*_+]”,pw))))>=1))
{
cat(“Password strength is Strong\n”)
}