Posted By

gatement on 07/24/09


Tagged

password random


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
webstic


Generate random password


 / Published in: Ruby
 

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

  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  

You need to login to post a comment.