1
A
回答
2
只是注意到你說'直接在數據庫中'。然後,你得到的第一條評論最有效。
如果您仍然可以通過軌道做(例如,在遷移),你可以試試這個:
user = User.find(...)
# set plain text password, it will run 'encrypted_password=' under the hood
user.password = "new password"
user.save
之後,你可能想要發送電子郵件通知或重置authentication_token,根據您的情況
。
1
@ cjm2671,簡短答案是否定的,你不應該。見設計是怎麼做的https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L4
# Verifies whether an password (ie from sign in) is the user password.
def valid_password?(password)
return false if encrypted_password.blank?
bcrypt = ::BCrypt::Password.new(encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
Devise.secure_compare(password, encrypted_password)
end
爲什麼你想直接做在DB?
如果您需要,您需要在數據庫上使用BCrypt(例如PostgreSQL的pgcrypto)和值self.class.peper
。我假設bcrypt.salt
將由BCrypt提供。
UPDATE:
我開始懷疑是可能的,我跳到迅速pgcrypto,但它似乎並沒有做你想做的。
相關問題
- 1. 在數據庫中重置Wordpress密碼
- 2. 在數據庫上設置密碼
- 3. 爲SQLite v3數據庫設置密碼
- 4. 爲Android Sqlite數據庫設置密碼
- 5. 在SQL 2005中爲數據庫設置密碼
- 6. 在Django中重置密碼
- 7. 在PostgreSQL中設置密碼
- 8. java密鑰庫和密碼設置
- 9. 重置密碼時設計中斷
- 10. 如何在codeigniter中設置重置密碼功能?
- 11. 重置根密碼後,建立數據庫連接時出錯
- 12. C#nHibernate以編程方式設置數據庫密碼
- 13. Microsoft Access數據庫:如何刪除用戶與密碼設置
- 14. 如何設置基於Web的密碼數據庫
- 15. 爲Cassandra數據庫設置用戶名和密碼
- 16. 設置的Crystal Reports Jet數據庫密碼編程
- 17. PHP密碼重置
- 18. Node.js密碼重置
- 19. Webmatrix重置密碼
- 20. Laravel重置密碼
- 21. 密碼重置在codeigniter
- 22. 重置PBKDF2中的密碼
- 23. 重置加密密碼
- 24. codeigniter設置密碼!
- 25. iphone設置密碼
- 26. 設置密碼NTAG213
- 27. 設計 - 可恢復(密碼重置)
- 28. 如何在我的本地數據庫.mdf文件中設置密碼C#?
- 29. PHP:在數據庫中設置密碼字段的最大長度是多少?
- 30. 數據庫設計 - 配置/設置表
'update user set password = crypt_function('new password here')'? – 2013-02-28 17:29:30