This tutorial explains how to create password generator utility with R.
R Function - Password Generator
Features -
- Each password contains numeric, special character, lowercase letter and uppercase letter.
- Flexibility to define the length of a password
- Flexibility to specify the number of passwords you want to generate
password.generator <- function(len, n){
dummydt=data.frame(matrix(ncol=0,nrow=n))
num <- 1:9
spcl <- c("!", "#", "$", "%", "&", "(", ")", "*", "+", "-", "/", ":",
";", "<", "=", ">", "?", "@", "[", "^", "_", "{", "|", "}", "~")
comb <- c(num, spcl, letters, LETTERS)
p <- c(rep(0.035, 9), rep(0.015, 25), rep(0.025, 52))
password<-replicate(nrow(dummydt),paste0(sample(comb, len, TRUE, prob = p), collapse = ""))
dummydt$password<-password
return(dummydt)
}
PasswrdFile = password.generator(len = 8, n = 100)
Parameters -
- len - Length of a password
- n - number of passwords you want to generate
With this code you generate n passwords rather than one at a time.
ReplyDeleteSubstitute the line dummydt=data.frame(matrix(ncol=0,nrow=n)) by dummydt=data.frame(matrix(ncol=0,nrow=1)) will generate only one password at a time.