in devise rails gem,這兩個有什麼區別?devise:password and:encrypted_password
我已經在生成的模式中看到:encrypted_password
字段,但沒有看到:password
字段。
任何解釋,如果這兩個互相連接?
in devise rails gem,這兩個有什麼區別?devise:password and:encrypted_password
我已經在生成的模式中看到:encrypted_password
字段,但沒有看到:password
字段。
任何解釋,如果這兩個互相連接?
password
是用戶設置爲密碼的純文本(純文本密碼不應存儲在任何地方)。 encrypted_password
這是此密碼的加密版本。您可能想要閱讀SecurePassword。
Devise::Models::DatabaseAuthenticatable
有一個二傳手:
def password=(new_password)
@password = new_password
self.encrypted_password = password_digest(@password) if @password.present?
end
所以,你應該設置密碼,如果有一個password
場,設計將其加密的照顧。
正如@spickermann已經指出的那樣 - 純文本密碼不應該存儲在任何地方,並且應該從日誌/錯誤消息等中過濾掉,因爲這會產生巨大的安全風險:加密密碼泄漏並非完全無害,但沒有那麼危險。
:password
是用戶通過表單設置的密碼。
:encrypted_password
是什麼存儲在您的數據庫和檢索創建用戶會話。
本質上,:encrypted_password
是一個散列和鹽漬版本:password
,可以安全地存儲在您的數據庫中。如果您需要更多信息,請參閱this answer,瞭解爲何不應在數據庫中存儲純文本密碼。