本文介绍了BCrypt的Rails固定装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了BCrypt密码固定装置的问题:我的User模型都是用has_secure_passwordvalidates_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.

关键是BC​​rypt使用passwordpassword_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固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:59