def authenticate(self, password): """ Compares the given password in a secure way with a value stored in database to determine if the password is correct or not. :param password: The password to be verified if it is the correct password for the given user. :return: True if the authentication was successful and the password is correct """ proposed = password.encode('utf-8') hashed = self.password.encode('utf-8') return verify_scryptsalsa208sha256(hashed, proposed)
def authenticate(self, password): """ Compares the given password in a secure way with a value stored in database to determine if the password is correct or not. :param password: The password to be verified if it is the correct password for the given user. :return: True if the authentication was successful and the password is correct """ proposed = password.encode('utf-8') serialized = self.password.encode('utf-8') if serialized.startswith(b'$7$'): res = verify_scryptsalsa208sha256(serialized, proposed) else: raise ValueError('Unknown serialization format') return res