Configurable default password scheme used for passwords

This commit is contained in:
Daniel Trnka
2017-09-02 17:36:22 +02:00
parent 1c0717e3db
commit da7c39263c
4 changed files with 11 additions and 6 deletions

View File

@@ -30,7 +30,8 @@ default_config = {
'BABEL_DEFAULT_LOCALE': 'en',
'BABEL_DEFAULT_TIMEZONE': 'UTC',
'ENABLE_CERTBOT': False,
'CERTS_PATH': '/certs'
'CERTS_PATH': '/certs',
'PASSWORD_SCHEME': 'SHA512-CRYPT'
}
# Load configuration from the environment if available

View File

@@ -169,14 +169,14 @@ class User(Base, Email):
'CRYPT': "des_crypt"}
pw_context = context.CryptContext(
schemes = scheme_dict.values(),
default='sha512_crypt',
default=scheme_dict[app.config['PASSWORD_SCHEME']],
)
def check_password(self, password):
reference = re.match('({[^}]+})?(.*)', self.password).group(2)
return User.pw_context.verify(password, reference)
def set_password(self, password, hash_scheme='SHA512-CRYPT', raw=False):
def set_password(self, password, hash_scheme=app.config['PASSWORD_SCHEME'], raw=False):
"""Set password for user with specified encryption scheme
@password: plain text password to encrypt (if raw == True the hash itself)
"""