ruby - Generate a password string of fixed length with certain required criteria (Capitals, numbers, special characters) -


i'm trying generate secure passwords of length meet criteria.

e.g. want (say) 10 letter password that:

has @ least 1 capital letter

has @ least 1 lower case letter

has @ least 1 number

has @ least 1 underscore (or other character, underscore due restrictions underscores accepted)

i've tried

securerandom.url_safebase64(10) 

but generates strings long , doesn't guarantee presence of each restriction.

wondering if there's easy way...

low = ('a'..'d').to_a  = ('a'..'z').to_a num = ('0'..'9').to_a u   = ['_'] = low + + num + u pw  = (low.sample(1) +         up.sample(1) +         num.sample(1) +         u.sample(1) +        any.sample(6)).shuffle.join 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -