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. 爲Azure數據庫重置密碼
- 4. 爲Android Sqlite數據庫設置密碼
- 5. 爲SQLite v3數據庫設置密碼
- 6. 在SQL 2005中爲數據庫設置密碼
- 7. 在Django中重置密碼
- 8. 在PostgreSQL中設置密碼
- 9. java密鑰庫和密碼設置
- 10. 將密碼設置爲我的sql中的單個數據庫
- 11. 如何在SQLite數據庫上設置密碼?
- 12. 重置密碼時設計中斷
- 13. 如何在codeigniter中設置重置密碼功能?
- 14. 重置根密碼後,建立數據庫連接時出錯
- 15. xml配置文件中的HA-JDBC數據庫密碼解密
- 16. 設置的Crystal Reports Jet數據庫密碼編程
- 17. 如何爲數據庫設置用戶名和密碼?
- 18. 從SQL數據庫獲取用戶名和密碼等設置
- 19. C#nHibernate以編程方式設置數據庫密碼
- 20. Microsoft Access數據庫:如何刪除用戶與密碼設置
- 21. 如何將變量設置爲數據庫密碼到pom.xml
- 22. 爲單個數據庫設置沒有密碼的root
- 23. 如何設置基於Web的密碼數據庫
- 24. 爲Cassandra數據庫設置用戶名和密碼
- 25. PHP密碼重置
- 26. Webmatrix重置密碼
- 27. Laravel重置密碼
- 28. CMDBuild密碼重置
- 29. 重置PBKDF2中的密碼
- 30. 密碼重置在codeigniter
'update user set password = crypt_function('new password here')'? – 2013-02-28 17:29:30