1
00:00:00,440 --> 00:00:03,530
So up next, let's set up that utils function.

2
00:00:03,530 --> 00:00:07,370
And again, this is something that I encourage you to.

3
00:00:07,910 --> 00:00:11,990
Try setting up yourself and then just compare the results.

4
00:00:12,230 --> 00:00:15,410
So in my case I'm going to go to Utils.

5
00:00:15,710 --> 00:00:21,440
I'm going to create a new file and in this case I'm going to call this password.

6
00:00:22,100 --> 00:00:27,460
Utils since we'll also need one to compare the password.

7
00:00:27,470 --> 00:00:29,750
So this one is for hashing.

8
00:00:29,750 --> 00:00:36,830
But then of course once the user logs in, we want to compare the password now in order to speed this

9
00:00:36,830 --> 00:00:37,400
up.

10
00:00:37,490 --> 00:00:39,110
I will copy some stuff.

11
00:00:39,110 --> 00:00:44,750
So in this case we won't use the bcrypt in the register.

12
00:00:45,580 --> 00:00:47,440
In the auth controller.

13
00:00:47,590 --> 00:00:49,810
Actually, we'll set up the import over here.

14
00:00:50,710 --> 00:00:52,540
Then we want to come up with a function name.

15
00:00:52,540 --> 00:00:54,700
In my case, I'm going to go with hash.

16
00:00:55,870 --> 00:00:58,990
Password is going to be a sync.

17
00:00:59,080 --> 00:01:00,120
And you know what?

18
00:01:00,130 --> 00:01:01,380
I forgot to export.

19
00:01:01,390 --> 00:01:04,989
So we want to go here with export const hash password.

20
00:01:05,850 --> 00:01:07,830
We're not looking for wreck and rage.

21
00:01:07,860 --> 00:01:10,230
We're looking for the password value.

22
00:01:11,080 --> 00:01:14,220
And then as far as the logic, same deal.

23
00:01:14,230 --> 00:01:19,660
We want to create the salt, we want to hash the password and we want to return the hash password.

24
00:01:19,840 --> 00:01:25,180
So let's go over here, take these two lines of code.

25
00:01:26,090 --> 00:01:27,470
Now for some reason.

26
00:01:28,630 --> 00:01:31,180
I opened up an extra screen.

27
00:01:31,180 --> 00:01:32,620
That's not what I wanted.

28
00:01:32,650 --> 00:01:34,330
Let's go to password utils.

29
00:01:34,360 --> 00:01:34,960
Okay.

30
00:01:35,080 --> 00:01:38,350
And before we set up the return, we want to fix it over here.

31
00:01:38,470 --> 00:01:44,140
Notice it's not going to be Req.body password since we're passing it as a parameter.

32
00:01:44,170 --> 00:01:49,480
We want to go here with password and then we want to go with hashed password.

33
00:01:49,480 --> 00:01:51,070
So that's what we want to return.

34
00:01:51,100 --> 00:01:54,670
Now we want to navigate back to auth controller.

35
00:01:54,970 --> 00:01:58,990
And essentially I want to set up that variable again from the scratch.

36
00:01:58,990 --> 00:02:05,320
I'm going to go with hashed password and this is going to be equal to my hash password, but we do need

37
00:02:05,320 --> 00:02:11,350
to remember that it is asynchronous, so we want to stick await in front of it and then we want to pass

38
00:02:11,350 --> 00:02:14,260
in req dot body and password.

39
00:02:14,980 --> 00:02:17,680
Since that's where the password is located.

40
00:02:17,710 --> 00:02:18,760
Then let's save.

41
00:02:18,760 --> 00:02:24,300
We're going to navigate to register user and essentially you want to set up unique email.

42
00:02:24,310 --> 00:02:27,010
So in my case, I'm going to go with Peter.

43
00:02:27,010 --> 00:02:33,880
And then if everything is correct, we should be able to see the hashed password in the database.

44
00:02:33,880 --> 00:02:35,520
So let's try it out over here.

45
00:02:35,530 --> 00:02:42,820
Like I said, I'm going to switch it to Peter, then we'll make a request and if I see message user

46
00:02:42,820 --> 00:02:46,090
created, it means that in the database.

47
00:02:46,930 --> 00:02:50,770
The password has been hashed for this user as well.

48
00:02:50,800 --> 00:02:51,580
Check it out.

49
00:02:51,580 --> 00:02:53,110
So this is my email.

50
00:02:53,140 --> 00:02:56,650
Peter And of course, this is the hashed value.

