Posted By


gatement on 07/24/09

Tagged


Statistics


Viewed 692 times
Favorited by 2 user(s)

Generate random password


/ Published in: Ruby
Save to your folder(s)

Generate random password.
e.g. reset user's password.


Copy this code and paste it in your HTML
  1. def generate_password(length=6)
  2. chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789'
  3. password = ''
  4. length.downto(1) { |i| password << chars[rand(chars.length - 1)] }
  5. password
  6. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.