gv5t8w
Last Updated: March 14, 2017
·
2.91K
· montas

Devise password generator

If you ever need simple random password generator for dummy data you can use this little route to generate one random password each refresh.

get 'random' => lambda { |env|
    [200, {"Content-Type" => "text/plain"}, [Devise.friendly_token.first(8)]]
}

I used this with Google Refine's ability to fill column with data from url to generate initial passwords for users that will have initial passwords generated for them.

2 Responses
Add your response

2659

Cool idea!

over 1 year ago ·
28719

This works in some (most ?) cases but bear in mind that this ignores any password complexity/validation rules that may be in place. My preference is to repeatedly attempt to generate a password from a set of predefined characters (e.g. alphanumeric, symbols) using Devse.password_length.min and Devise.password_regex.

Just be sure to set some limit on how many attempts it will make to avoid infinite loops if the seed character set is insufficient to satisfy the complexity requirements.

over 1 year ago ·