29 The function to hash the password for the security
31 password (str): The entered password
34 str: The hashed password
36 title =
"_hash_password"
37 self.
disp.log_debug(
"Enter hash password", f
"{title}")
38 if isinstance(password, bytes)
is False:
39 password = bytes(password, encoding=
"utf-8")
40 self.
disp.log_debug(
"Start register endpoint", f
"{title}")
42 safe_password = bcrypt.hashpw(password, salt)
43 return safe_password.decode(
"utf-8")
47 The function to check the entered password with the hashed password
49 password (str): The entered password
50 password_hash (bytes): The hashed password
53 bool: True if it's the same, False if not
55 msg = f
"password = {type(password)}, "
56 msg += f
"password_hash = {type(password_hash)}"
57 self.
disp.log_debug(msg,
"check_password")
58 if isinstance(password, bytes)
is False:
59 password = password.encode(
"utf-8")
60 if isinstance(password_hash, bytes)
is False:
61 password_hash = password_hash.encode(
"utf-8")
62 msg = f
"password = {type(password)}, password_hash = "
63 msg += f
"{type(password_hash)}"
64 self.
disp.log_debug(msg,
"check_password")
65 return bcrypt.checkpw(password, password_hash)