That wasn't nice and easy.
And once we have our say in place now, it's finally hash the password and a side note in between the
videos.
I did remove my John user from database, so my postman, I'll be able to reuse of the values and essentially
the steps are falling.
First, we want to start with Uninstall.
So let me stop the server and discuss clearly console and I sent out a nice, nifty trick is going with
control and out, which pretty much moves it.
So for many years, I've been typing clear, but you can actually do it with control and health.
And of course not is on a Mac.
But you can go to my Twitter and you can find one of the tweets where you'll find the options for Windows
as well.
And we want to go with npm install be crypt.
So let me grab my first line of code copy and paste, and then let's star up our server.
And once our server is up and running, it actually looks like I forgot to add import the script in
the user model.
Now it is kind of self-explanatory, but let me just add it over here.
So let me go with b script and I'm going to call the actual variable B script.
But remember that that is coming from the library.
So Bikram jazz.
And let's add here import, import in and use the online model.
Let's say that I want and actually go to the user model and look for the beta version.
So we're looking for already package.
And like I said, I'm going to call this be just a little bit faster.
But keep in mind where it's coming from.
So be crypt jazz and the line where we want to keep on scrolling, keep on scrolling and in our preset
hook, we want to set up the functionality.
Now how is the functionality going to look like?
Well, we'll have a few functions.
First of all.
There's going to be a hash function where we pass in the password as well as the salt.
But before we can do that, we'll have to generate the salt now.
Looks like I have a typo here.
So it should be James salt.
Both of them are going to be a synchronous.
And you can think of this one as creating extra characters.
And these are just ROMs that you present.
Keep in mind that the more iPhones you have.
Yes, it's going to be more secure, but it will also take longer time.
And I believe 10 is a default and essentially 10 rounds is solid approach.
So let's navigate back to our user and then right away, let's set this up as a sync function.
And what do we want to do?
Well, we want to generate that salt.
Correct.
So we go here with Konst salt is equal to and that a weight of the variable name.
Gosh, that is bigger than that.
And then I'm looking for gen salt and then we want to pass in the realms, which is going to be 10.
And what is the next step?
Well, then I want to set my password, the one that I will have in the document equal to something.
Now what is that something?
Well, that is the value that I'm going to get back from the hash one where again, I'll pass in the
password that is provided by the user and I'll set up the document password equal to a hash value.
Hopefully, that makes sense.
So let's go over here with this dot password.
Remember, we're just logged in a previous video, so we know that we can access it and we're going
to go with await when I can script that.
And now we're looking for to hash and instead of the hash, we're passing this dot password.
So again, whatever the user is providing, I'm on the second value is going to be the salt.
And once we set this one up, let's try it one more time and a postman.
And as a result, we should see our password nicely hashed when we stored in our database.
So let me navigate to my post, man, and let me send it one more time.
And what do you know her name, email and look at the password?
Now, keep in mind that, of course, we're not going to be sending back this password to a frontend.
So this is just temporary.
Just so we can see whether our functionality works.
Yes.
Eventually, we'll actually remove the password from our response because it's not a good approach to
send those passwords in the first place.
And with this in place now, we can start focusing on setting up the JSON web token.