March 2019
Beginner to intermediate
324 pages
7h 17m
English
Now, let's write the code that will compare the saved hashed passwords with passwords that are provided by users who are attempting to log in.
We just need another method from the bcrypt package to compare our saved hash with the incoming password:
func checkPassword(existingHash, incomingPass string) bool { //this method will return an error if the hash does not match the provided password string return bcrypt.CompareHashAndPassword([]byte(existingHash), []byte(incomingPass)) == nil}
Next, we need to add code to the SignInUser method so that we can retrieve the hashed passwords of customers who are trying to sign in. Then, we can compare passwords. If the passwords don't match, we return an error. If they do, we continue ...
Read now
Unlock full access