To validate a password using regular expression in R
Load the password
Check whether the length of the password is greater than zero
Check whether it contains at least one upper case letter
Check whether it contains at least one lower case letter
Check whether it contains at least one digit
Check whether it doesn’t contain white space
If all the above conditions are met then it is a good choice of password
pw=readline(prompt = “Enter the password : “)
i=0
if(nchar(pw)<8)
{
i=1
cat(“The Password is too short\n”)
}
if(grepl(“[[:upper:]]”,pw)==FALSE)
{
i=1
cat(“Password must contain atleast one Upper case letter\n”)
}
if(grepl(“[[:lower:]]”,pw)==FALSE)
{
i=1
cat(“Password must contain atleast one Lower case letter\n”)
}
if(grepl(“[[:digit:]]”,pw)==FALSE)
{
i=1
cat(“Password must contain atleast one digit\n”)
}
if(grepl(“[[:space:]]”,pw)==TRUE)
{
i=1
cat(“The password mustnot contain white space\n”)
}
if(i==0)
{
cat(“Good choice of password”)
}else
{
cat(“Please Retry”)
}