#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to validate strength of a password using regular expression in R?
Description

To validate strength of a password using regular expression in R

Process

  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

Sapmle Code

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”)
}

Screenshots