是的,如果使用 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 https://github.com/mattupstate/flask-security/issues/268
可以在代码中验证,从 encrypt 走到 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 https://pythonhosted.org/passlib/password_hash_api.html#passlib.ifc.PasswordHash.encrypt
请注意,每次调用 encrypt() 都会生成一个新的盐,