Merge pull request #1330 from caraar12345/aaroncarson/fix/1329

Fix #1329
This commit is contained in:
Matt Scott 2022-12-13 20:54:26 -05:00 committed by GitHub
commit 1a05518018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,6 +108,7 @@ class User(db.Model):
def check_password(self, hashed_password):
# Check hashed password. Using bcrypt, the salt is saved into the hash itself
if hasattr(self, "plain_text_password"):
if self.plain_text_password != None:
return bcrypt.checkpw(self.plain_text_password.encode('utf-8'),
hashed_password.encode('utf-8'))
return False
@ -422,8 +423,12 @@ class User(db.Model):
self.role_id = Role.query.filter_by(
name='Administrator').first().id
if hasattr(self, "plain_text_password"):
if self.plain_text_password != None:
self.password = self.get_hashed_password(
self.plain_text_password) if hasattr(self, "plain_text_password") else '*'
self.plain_text_password)
else:
self.password = '*'
if self.password and self.password != '*':
self.password = self.password.decode("utf-8")
@ -460,6 +465,7 @@ class User(db.Model):
# store new password hash (only if changed)
if hasattr(self, "plain_text_password"):
if self.plain_text_password != None:
user.password = self.get_hashed_password(
self.plain_text_password).decode("utf-8")
@ -476,9 +482,11 @@ class User(db.Model):
user.firstname = self.firstname if self.firstname else user.firstname
user.lastname = self.lastname if self.lastname else user.lastname
if hasattr(self, "plain_text_password"):
if self.plain_text_password != None:
user.password = self.get_hashed_password(
self.plain_text_password).decode(
"utf-8") if hasattr(self, "plain_text_password") else user.password
self.plain_text_password).decode("utf-8")
if self.email:
# Can not update to a new email that