So let's try out our encryption library, and the first thing I'm going to do is fix a typo in encryption,
not go down here, I misspelled Decrypt.
So let's fix that.
That just makes me feel better.
OK, so that's fixed.
Now, back in handlers go right now, we're just passing the email that we received right here.
And what I'm going to do is get rid of that and come up here and just assign that to a variable called
email.
OK, so we have that.
Now, we still want to verify the signature and we still want to make sure it's not expired, but down
here, after we check the expiration of the link, let's actually encrypt it.
So we'll create a variable called Encrypt Tor, which may not be a word, but I'm going with it.
That's a sign the value of from the encryption package we just made got encryption and we populate its
key with cost to a slice of bytes, which it has to be configured.
Not secret key.
OK, that gives us a variable we can use to encrypt our email.
So let's create a variable called encrypted email, encrypted email and potentially an error are assigned
the value of encrypt or don't encrypt.
And we hand it email and we check for an error.
So we'll do the same thing I've been doing right along.
And again, you can do whatever you wish.
At this point, so we'll say encryption failed
and once that's actually encrypted, that's what we're going to pass to reform.
And that will display an encrypted version of the email.
And nobody will be able to guess the correct encryption encryption algorithm if they want to change
the emails.
So that solves that problem.
And, of course.
We need to fix this, too, if error is not equal to no, I was sloppy.
So let's stop now on the back end.
We need to go to Handler's Dash API, don't go, which is right here.
And we want to find the reset password function, which is right about here.
After we read the JSON and before we look up the user, we have to decrypt that email.
So we'll just go back over and use our encrypted package so we'll create a variable called encrypted.
And that's a sign the value of from our encryption package dot encryption and it's key is a sign the
value of a slice of bytes.
And we want app dot, config, dot secret key.
And then we use that variable to decrypt what we received in the payload.
So real email and potentially error are a sign the value of encrypt or decrypt.
And we hand it payload the email and we check for an error.
If error is not equal to nil,
then I'll just do the same thing I've been doing right along.
So I'll copy this stuff and paste it in here.
And at this point, we're not going to get the user by payload email because that's encrypted.
Instead, we use the decrypted value.
And we shouldn't have to do anything else, so let's try writing this, so make stop, make start.
Let's go over to our Web browser and we'll start the whole process right from the beginning.
So I'll open this up and go to mail traffic
and go to my inbox.
It's empty and let's go to login.
Forgot my password.
Let's put in an example.
Dot com.
Send the link.
Go to mantrap.
There it is.
Let's click on this.
And now let's give you the source and see what's in that payload variable.
So all the way down to the JavaScript.
And there's an encrypted version of our email right there, and I would not be able to guess what to
use to make that point to somebody else's email.
Now let's make sure it works.
So my password, I will change it to password three password three reset password.
I should take me to the login screen and I'll put in admin at example, dot com and password three,
and if I typed that right, I should get it and I do.
So that works really well.
And the nice thing about this, of course, is we have that encryption functionality available to us
anywhere we need it.
So if I want to store encrypted values in the database for really sense of sensitive information, I
can use those two functions to encrypt and decrypt at will.
And that makes things ever so much simpler.
All right, let's move on.