Search code examples
rpasswordsanalytics

R password analysis


I want to analyse passwords for a uni project. I would like to give R 50 passwords to analyse, looking at the combinations of lower case, upper case, numbers and special characters. I am working with some R code, taken from https://datadrivensecurity.info/blog/posts/2014/Feb/ripal/ and I cant get it work.

Specifically R is only recognising lower case letter passwords, I cant get it to recognise the passwords which have other combinations of characters, such as upper and lower case, lower and special etc, the code keeps coming back with 0% when I know there are passwords which fit that criteria in 50 from my data frame.

Is there something I am doing wrong, are my arguments / R code correct?

Any help greatly appreciated.

  contains.only.lower.alpha <- sum(grepl("^[a-z]+$",Final_DF$Pswd))
contains.only.upper.alpha <- sum(grepl("^[A-Z]+$",Final_DF$Pswd))
contains.only.numeric <- sum(grepl("^[0-9]+$",Final_DF$Pswd))
contains.only.special <- sum(grepl("^[:punct:]+$",Final_DF$Pswd))

contains.both.lower.and.upper <- only.lower.alpha + only.upper.alpha
contains.both.lower.and.numeric <- only.lower.alpha + only.numeric
contains.both.lower.and.special <- only.lower.alpha + only.special
contains.both.upper.and.numeric <- only.upper.alpha + only.numeric
contains.both.upper.and.special <- only.upper.alpha + only.special
contains.both.numeric.and.special <- only.numeric + only.special

contains.lower.upper.and.numeric <- only.lower.alpha + only.upper.alpha + only.numeric
contains.lower.upper.numeric.and.special <- only.lower.alpha + only.upper.alpha + only.numeric + only.special

print(sprintf("Only lowercase alpha = %d, (%3.3f%%)", only.lower.alpha, 100*(only.lower.alpha/50)))
print(sprintf("Only uppercase alpha = %d, (%3.3f%%)", only.upper.alpha, 100*(only.upper.alpha/50)))
print(sprintf("Only numeric = %d, (%3.3f%%)", only.numeric, 100*(only.numeric/50)))
print(sprintf("Only special = %d, (%3.3f%%)", only.special, 100*(only.special/50)))

print(sprintf("Both lower and upper alpha = %d, (%3.3f%%)", both.lower.and.upper, 100*(both.lower.and.upper/50)))
print(sprintf("Both lower and numeric = %d, (%3.3f%%)", both.lower.and.numeric, 100*(both.lower.and.numeric/50)))
print(sprintf("Both lower and special = %d, (%3.3f%%)", both.lower.and.special, 100*(both.lower.and.special/50)))
print(sprintf("Both upper and numeric = %d, (%3.3f%%)", both.upper.and.numeric, 100*(both.upper.and.numeric/50)))
print(sprintf("Both upper and special = %d, (%3.3f%%)", both.upper.and.special, 100*(both.upper.and.special/50)))
print(sprintf("Both.numeric.and.special = %d, (%3.3f%%)", both.numeric.and.special, 100*(both.numeric.and.special/50)))

print(sprintf("Lower.upper.and.numeric = %d, (%3.3f%%)", lower.upper.and.numeric, 100*(lower.upper.and.numeric/50)))
print(sprintf("Lower.upper.numeric.and.special = %d, (%3.3f%%)", lower.upper.numeric.and.special, 100*(lower.upper.numeric.and.special/50)))

These are the 50 passwords I am working with, which I have generated using R, I will regenerate these to get a greater spread to include all special etc after I know I can get the code to work.

> Final_DF$Pswd

[1] "monkey" "iloveyou" "dragon" "jbI2pnK$xi" "password" "computer" "!qessw"
[8] "tUNh&SSm6!" "sunshine" "wYrUeWV" "superman" "samsung" "utoXGe6$" "master"
[15] "wjZC&OvXX" "0R1cNTm9sGir" "Fbuu2bs89?" "pokemon" "secret" "x&W1TjO59" "buster"
[22] "purple" "shine" "flower" "marina" "Tg%OQT$0" "SbDUV&nOX" "peanut"
[29] "angel" "?1LOEc4Zfk" "computer" "spiderman" "nothing" "$M6LgmQgv$" "orange"
[36] "knight" "american" "outback" "TfuRpt3PiZ" "air" "surf" "lEi2a$$eyz"
[43] "date" "V$683rx$p" "newcastle" "estate" "foxy" "ginger" "coffee"
[50] "legs"


Solution

  • Figured it out, needed combination of logic statements for each password character combination

    grepl("^(?!.*[[:lower:]]).*$",df, perl = TRUE)