2023-01-25 19:13:00 -05:00
|
|
|
"""
|
2023-05-31 13:51:35 -04:00
|
|
|
Auth module
|
2023-01-25 19:13:00 -05:00
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2023 Concordia CERC group
|
|
|
|
Project Coder Peter Yefi peteryefi@gmail.com
|
|
|
|
"""
|
|
|
|
|
2022-12-08 20:54:47 -05:00
|
|
|
import bcrypt
|
|
|
|
|
|
|
|
|
|
|
|
class Auth(object):
|
2023-05-31 13:51:35 -04:00
|
|
|
"""
|
|
|
|
Auth class
|
|
|
|
"""
|
2022-12-08 20:54:47 -05:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def hash_password(password: str) -> str:
|
|
|
|
"""
|
|
|
|
Hashes a password
|
|
|
|
:param password: the password to be hashed
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(14)).decode('utf-8')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def check_password(password: str, hashed_password) -> bool:
|
|
|
|
"""
|
|
|
|
Hashes a password
|
|
|
|
:param password: the password to be checked
|
|
|
|
:param hashed_password: the hashed password
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
return bcrypt.checkpw(password.encode('utf-8'), hashed_password.encode('utf-8'))
|