add facilities to rehash on login passwords if parameters change

This commit is contained in:
Arvedui
2019-03-03 00:17:27 +01:00
parent dd2e8ab360
commit ab0926f916
2 changed files with 18 additions and 0 deletions
+10
View File
@@ -86,6 +86,16 @@ class PasswordHasher(with_metaclass(MetaHasher, object)):
hashed_value
)
def needs_rehash(self, hashed_value):
"""Check if the provided hash needs rehasing accoring to the current
parameters
:param str hashed_value: hased password
:rtype bool
:return: True if the password needs rehash, false otherwise
"""
return False
@classmethod
def get_password_hashers(cls):
"""Return all the PasswordHasher supported by Modoboa"""
+8
View File
@@ -52,6 +52,14 @@ def dologin(request):
)
user.set_password(form.cleaned_data["password"])
user.save()
if pwhash.needs_rehash(user.password):
logging.info(
_("Password hash parameter missmatch. "
"Updating %s password"),
user.username
)
user.set_password(form.cleaned_data["password"])
user.save()
login(request, user)
if not form.cleaned_data["rememberme"]: