How to auto-generate passwords in Rails Devise?

Use the Devise.friendly_token method:

password_length = 6
password = Devise.friendly_token.first(password_length)
User.create!(:email => 'someone@something.com', :password => password, :password_confirmation => password)

FYI: Devise.friendly_token returns a 20 character token. In the example above, we’re chopping off the first password_length characters of the generated token by using the String#first method that Rails provides.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)