Tuesday, September 25, 2007

method: generate_password

Generate a password. Make sure this goes hand-in-hand with encryption. You don't want to store passwords as-is in databases.


def generate_password(length = 6)
chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('1'..'9').to_a - ['o', 'O', 'i', 'I']
Array.new(length) { chars[rand(chars.size)] }.join
end


I got this from "here":http://www.rubyonrailsblog.com/articles/2006/09/29/ruby-on-rails-random-password-generator.

No comments: