r - Function to generate a random password -


i want generate random password employees function below. first attempt functions in r. need bit help.

genpsw <- function(num, len=8) {           # vorgaben für die passwortkonventionen festlegen             myarr  <- c("", 2, 3, 4, 5, 6, 7, 8, 9, "a", "b",                          "c", "d", "e", "f", "g", "h", "j", "k", "l", "m",                          "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",                          "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",                         "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",                          "!", "§", "$", "%", "&", "(", ")", "*")           # replicate wrapper common use of sapply repeated evaluation of expression            # (which involve random number generation).             replicate(num, paste(sample(myarr, size=len, replace=t), collapse=""))           # nrow of dataframe mitarbeiter            dim_mitarbeiter <- nrow(mitarbeiter)           for(i in 1:dim_mitarbeiter) {                         # random number generation                           set.seed(i)                         # generate passwort new variable password                         mitarbeiter$passwort <- genpsw(i)                           }  } 

with answer form floo0 i've changed function somthing that, doesn't work:

genpsw <- function(num, len=8) {           # vorgaben für die passwortkonventionen festlegen           sam<-list()           sam[[1]]<-1:9           sam[[2]]<-letters           sam[[3]]<-letters           sam[[4]]<-c("!", "§", "$", "%", "&", "(", ")", "*")            # nrow of dataframe mitarbeiter            dim_mitarbeiter <- nrow(mitarbeiter)           for(i in 1:dim_mitarbeiter) {                         # random number generation                             tmp<-mapply(sample,sam,c(2,2,2,2))                          # generate passwort new variable password                         mitarbeiter$passwort <- paste(sample(tmp),collapse="")           }  } 

what about

samp<-c(2:9,letters,letters,"!", "§", "$", "%", "&", "(", ")", "*") paste(sample(samp,8),collapse="") 

result this

"hkf§vvnd" 

caution: approch not enforce having capitals, numbers, , non alpha numeric symbols

edit:

if want enforce number of capitals, numbers, , non alpha numeric symbols go this:

sam<-list() sam[[1]]<-1:9 sam[[2]]<-letters sam[[3]]<-letters sam[[4]]<-c("!", "§", "$", "%", "&", "(", ")", "*")  tmp<-mapply(sample,sam,c(2,2,2,2)) paste(sample(tmp),collapse="") 

where c(2,2,2,2) specifies number of numbers, letters, capital letters , symbild (in order). result:

[1] "j$bp%5r3" 

edit2: produce new column in table mitarbeiter use

passwort<-replicate(nrow(mitarbeiter),paste(mapply(sample,sam,c(2,2,2,2)),collapse="")) mitarbeiter$passwort<-passwort 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -