问题描述
我正在尝试Devise如何与我的一个项目进行用户身份验证。有一个用户要求,他们的管理员应该能够不时地生成一批用户名和用户密码,然后管理员将向用户发送新的用户名和密码。
I am trying out how Devise works with one of my projects for user authentication. There is a user requirement that their admin should be able to generate a batch of username and user's password from time to time, and then the admin will email the new username and password to his users.
假设管理员在MySQL数据库上有直接SQL的知识,Devise可以识别生成的用户名/密码?谢谢!
Assume the admin has the knowledge of direct SQL on the MySQL database, how can the generated usernames/passwords recognized by Devise? Thanks!
推荐答案
使用方法:
password_length = 6
password = Devise.friendly_token.first(password_length)
User.create!(:email => '[email protected]', :password => password, :password_confirmation => password)
FYI: Devise.friendly_token
返回一个20个字符的令牌。在上面的例子中,我们通过使用方法。
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.
这篇关于如何在Rails Devise中自动生成密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!