February 2018
Intermediate to advanced
456 pages
9h 56m
English
We will now implement an authenticate method that will use the get method we just created.
First, let's create a new exception class that will be raised if there is a password mismatch:
class AuthenticationError(Exception):
pass
We can now create another method for our UserWrapper to authenticate users:
def authenticate(self, email, password):
user = self.get(email) # ①
if not bcrypt.checkpw(password.encode(), user.password): # ②
message = 'Incorrect password for {}'.format(email)
raise AuthenticationError(message) # ③
Read now
Unlock full access