在这里阅读了一些关于盐渍密码的信息后,似乎最好为每个用户使用一种独特的盐.我正在努力实现Flask-Security atm,从文档看来你只能设置一个全局盐:即SECURITY_PASSWORD_SALT ='thesalt'
问题:如何为每个密码制作一个独特的盐?
谢谢!
编辑:从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.
trevor.. 15
是的,如果使用bcrypt(以及其他方案,如des_crypt,pbkdf2_sha256,pbkdf2_sha512,sha256_crypt,sha512_crypt),Flask-Security会按设计使用每用户盐.
"SECURITY_PASSWORD_SALT"的配置仅用于HMAC加密.如果您使用bcrypt作为散列算法,Flask-Security使用passlib进行散列,并在散列过程中生成随机盐.问题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
请注意,每次调用encrypt()都会生成一个新的salt,
Chockomonkey.. 7
事实证明,如果你使用bcrypt,它会处理salting并将其与hash一起存储.所以我会去那条路!
感谢这个让我发现这个问题的主题:
我需要用bcrypt储存盐吗?
是的,如果使用bcrypt(以及其他方案,如des_crypt,pbkdf2_sha256,pbkdf2_sha512,sha256_crypt,sha512_crypt),Flask-Security会按设计使用每用户盐.
"SECURITY_PASSWORD_SALT"的配置仅用于HMAC加密.如果您使用bcrypt作为散列算法,Flask-Security使用passlib进行散列,并在散列过程中生成随机盐.问题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
请注意,每次调用encrypt()都会生成一个新的salt,
事实证明,如果你使用bcrypt,它会处理salting并将其与hash一起存储.所以我会去那条路!
感谢这个让我发现这个问题的主题:
我需要用bcrypt储存盐吗?