2014-09-19 70 views
5

在閱讀了一些有關鹽漬密碼的信息之後,似乎最好爲每個用戶使用一種獨特的鹽。我正在實施Flask-Security atm,並且從文檔中看到,您只能設置全局鹽:即SECURITY_PASSWORD_SALT ='thesalt'每位用戶使用Flask-Security的獨特鹽

問題:如何爲每個密碼創建獨特的salt?

謝謝!

編輯:來自Flask-Security上的文檔,我發現這個,似乎再次表明這個模塊僅僅使用一個單鹽來開箱即用所有密碼。

flask_security.utils.get_hmac(password) 
    Returns a Base64 encoded HMAC+SHA512 of the password signed with the salt 
    specified by SECURITY_PASSWORD_SALT. 
+1

一個全球性的鹽不是鹽。如果每個人都使用相同的鹽,那麼恰好具有相同密碼的兩個用戶將具有相同的哈希密碼。這就是鹽類預防的一種情況。 – 2014-09-19 20:45:39

+0

@MichaelBurr好的,這就是我想的......這就是爲什麼我很困惑。如何使用此設置爲每個密碼創建獨特的鹽?或者我必須重寫Flask-Security中內置的salting以執行此操作? – Chockomonkey 2014-09-19 21:30:36

+1

對不起 - 我對Flask一無所知。我只是在評論全球鹽的想法。 – 2014-09-19 21:54:07

回答

12

是,瓶,安全性也通過設計,如果使用bcrypt(和其他方案,如des_crypt,pbkdf2_sha256每個用戶都鹽, pbkdf2_sha512,sha256_crypt,sha512_crypt)。

'SECURITY_PASSWORD_SALT'的配置僅用於HMAC加密。如果使用bcrypt作爲散列算法,Flask-Security使用passlib進行散列,並在散列期間生成隨機鹽。此confustion在問題268指出:https://github.com/mattupstate/flask-security/issues/268

它可以在代碼進行驗證,從加密步行到passlib:

flask_security/utils.py(線143-151,39,和269)

def encrypt_password(password): 
    ... 
    return _pwd_context.encrypt(signed) 

_pwd_context = LocalProxy(lambda: _security.pwd_context) 

flask_security/core.py(269,244-251,和18)

pwd_context=_get_pwd_context(app) 

def _get_pwd_context(app): 
    ... 
    return CryptContext(schemes=schemes, default=pw_hash, deprecated=deprecated) 

from passlib.context import CryptContext 

最後從:https://pythonhosted.org/passlib/password_hash_api.html#passlib.ifc.PasswordHash.encrypt

注意,每個呼叫進行加密()產生新的鹽,

5

原來,如果您使用bcrypt,它會負責醃製並將其存儲在散列中。所以我會走這條路!

由於這個話題這導致我這一發現:

Do I need to store the salt with bcrypt?

+2

找到解決方案後回到自己的問題的榮譽。 – 2014-09-21 02:08:59

相關問題