Random Password Generator For Ruby
Join the DZone community and get the full member experience.
Join For FreeUnfriendly / easily mistaken characters (i o 0 1 l 0) are excluded.
def random_password(size = 8)
chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0)
(1..size).collect{|a| chars[rand(chars.size)] }.join
end
puts random_password.inspect
(July 14 - Fixed due to comment by friendly commenter below :))
Opinions expressed by DZone contributors are their own.
Comments