R/charset_size.R

Defines functions charset_size

Documented in charset_size

#' Character Set Size
#'
#' Determine the Charset size based on what combination of characters has been used in the password
#'
#' @param x a character string of the password to test
#' @return a numeric value of the charset size
#'
#' @export

charset_size <- function(x)
{
    CHARSET <- c(0, 0, 0, 0)

    if (isTRUE(stringr::str_detect(x , '[:punct:]'))) {
        CHARSET[1] <- 22
    }

    if (isTRUE(stringr::str_detect(x , '[:upper:]'))) {
        CHARSET[2] <- 26
    }

    if (isTRUE(stringr::str_detect(x , '[:lower:]'))) {
        CHARSET[3] <- 26
    }

    if (isTRUE(stringr::str_detect(x , '[:digit:]'))) {
        CHARSET[4] <- 10
    }

    CHARSET_SIZE <- sum(CHARSET)

    return(CHARSET_SIZE)
}
wilsontom/passwordStrength documentation built on March 29, 2020, 10:30 p.m.