问题描述
我遇到了BCrypt密码固定装置的问题:我的User
模型都是用has_secure_password
和validates_presence_of :password
设置的.
I'm having a problem with fixtures for BCrypt password:my User
model is both setup with has_secure_password
and validates_presence_of :password
.
关键是BCrypt使用password
和password_confirmation
,但是在模式中只有password_digest
字段.
The point is that BCrypt uses password
and password_confirmation
but in the schema there is only the password_digest
field.
灯具抱怨password
字段不存在.
如何避免这种情况?
谢谢
推荐答案
似乎是将灯具直接推送到数据库中.这意味着您需要在设备中使用password_digest:
而不是password:
Seems that fixtures are being pushed to the database directly. That means that instead of password:
you need password_digest:
in your fixtures:
test_user:
email: "[email protected]"
password_digest: <%= BCrypt::Password.create('testpassword', cost: 5) %>
当与has_secure_password
一起使用基于bcrypt的密码时.如注释中所述,cost
参数是可选的.如果您不使用它,则将使用明智的默认值.
when using bcrypt based passwords with has_secure_password
. As mentioned in the comments cost
argument is optional. If you don't use it a sensible default will be used.
这篇关于BCrypt的Rails固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!