So up next, let's set up that utils function.
And again, this is something that I encourage you to.
Try setting up yourself and then just compare the results.
So in my case I'm going to go to Utils.
I'm going to create a new file and in this case I'm going to call this password.
Utils since we'll also need one to compare the password.
So this one is for hashing.
But then of course once the user logs in, we want to compare the password now in order to speed this
up.
I will copy some stuff.
So in this case we won't use the bcrypt in the register.
In the auth controller.
Actually, we'll set up the import over here.
Then we want to come up with a function name.
In my case, I'm going to go with hash.
Password is going to be a sync.
And you know what?
I forgot to export.
So we want to go here with export const hash password.
We're not looking for wreck and rage.
We're looking for the password value.
And then as far as the logic, same deal.
We want to create the salt, we want to hash the password and we want to return the hash password.
So let's go over here, take these two lines of code.
Now for some reason.
I opened up an extra screen.
That's not what I wanted.
Let's go to password utils.
Okay.
And before we set up the return, we want to fix it over here.
Notice it's not going to be Req.body password since we're passing it as a parameter.
We want to go here with password and then we want to go with hashed password.
So that's what we want to return.
Now we want to navigate back to auth controller.
And essentially I want to set up that variable again from the scratch.
I'm going to go with hashed password and this is going to be equal to my hash password, but we do need
to remember that it is asynchronous, so we want to stick await in front of it and then we want to pass
in req dot body and password.
Since that's where the password is located.
Then let's save.
We're going to navigate to register user and essentially you want to set up unique email.
So in my case, I'm going to go with Peter.
And then if everything is correct, we should be able to see the hashed password in the database.
So let's try it out over here.
Like I said, I'm going to switch it to Peter, then we'll make a request and if I see message user
created, it means that in the database.
The password has been hashed for this user as well.
Check it out.
So this is my email.
Peter And of course, this is the hashed value.