def test_verify_hash(in_app_context): data = hash_data("hellö") assert verify_hash(data, "hellö") is True assert verify_hash(data, "hello") is False legacy_data = hashlib.md5(encode_string("hellö")).hexdigest() assert verify_hash(legacy_data, "hellö") is True assert verify_hash(legacy_data, "hello") is False
def get_hmac(password): from flask_security.utils import encode_string """Returns a Base64 encoded HMAC+SHA512 of the password signed with the salt specified by ``PASSWORD_SALT``. :param password: The password to sign """ salt = current_app.config.get('PASSWORD_SALT') if salt is None: raise RuntimeError('The configuration value `PASSWORD_SALT` must ' 'not be None when the value of `PASSWORD_HASH` is ' 'set to "%s"' % salt) h = hmac.new(encode_string(salt), encode_string(password), hashlib.sha512) return base64.b64encode(h.digest())
def test_verify_hash(in_app_context): data = hash_data(u'hellö') assert verify_hash(data, u'hellö') is True assert verify_hash(data, u'hello') is False legacy_data = hashlib.md5(encode_string(u'hellö')).hexdigest() assert verify_hash(legacy_data, u'hellö') is True assert verify_hash(legacy_data, u'hello') is False
def get_hmac(password): from flask_security.utils import encode_string """Returns a Base64 encoded HMAC+SHA512 of the password signed with the salt specified by ``PASSWORD_SALT``. :param password: The password to sign """ salt = current_app.config.get('PASSWORD_SALT') if salt is None: raise RuntimeError( 'The configuration value `PASSWORD_SALT` must ' 'not be None when the value of `PASSWORD_HASH` is ' 'set to "%s"' % salt) h = hmac.new(encode_string(salt), encode_string(password), hashlib.sha512) return base64.b64encode(h.digest())
def test_legacy_hash(in_app_context, data): legacy_hash = hashlib.md5(encode_string(data)).hexdigest() new_hash = hash_data(data) assert legacy_hash == new_hash