1
00:00:01,120 --> 00:00:02,290
In this video.

2
00:00:02,290 --> 00:00:05,530
Let's finish up with the user registration.

3
00:00:05,920 --> 00:00:14,860
The problem that we are facing is that if we leave as it is, that is how we are registering the user

4
00:00:14,860 --> 00:00:16,920
and save it into our division.

5
00:00:17,020 --> 00:00:23,740
Here you can see we are saving the plane password inside our database.

6
00:00:23,740 --> 00:00:27,840
So let's say in future our application compromise.

7
00:00:27,850 --> 00:00:33,070
In that way we are exposing this particular user into problems.

8
00:00:33,100 --> 00:00:39,670
It can happen that this user uses the same password for his or her banking transaction.

9
00:00:40,180 --> 00:00:44,380
So in this way we are exposing this user into problem.

10
00:00:44,380 --> 00:00:47,890
If a hacker got to know the details about the user.

11
00:00:47,980 --> 00:00:54,840
So instead of saving the plain password, we are going to save random string of characters into our.

12
00:00:55,480 --> 00:00:59,100
So we need to install a package to get it done.

13
00:00:59,110 --> 00:01:07,660
So let's get back to our terminal and let's shut down and let me clear the terminal and install a package

14
00:01:07,660 --> 00:01:09,670
called Big Crypt JS.

15
00:01:12,940 --> 00:01:14,650
And it just finished installing.

16
00:01:14,660 --> 00:01:17,320
So let me restart the server.

17
00:01:18,290 --> 00:01:26,330
If you have taken some of my courses, you can see that I always hash the user password inside the module,

18
00:01:26,360 --> 00:01:30,300
but for this one I'm going to do it inside the controller.

19
00:01:30,320 --> 00:01:39,260
So let's get back to the user controller and let's require the package as be equipped, be equipped.

20
00:01:39,260 --> 00:01:39,760
Geez.

21
00:01:39,770 --> 00:01:48,140
So let me bring the custom input below the default ones or the installed packages.

22
00:01:48,140 --> 00:01:49,630
So now here we go.

23
00:01:49,790 --> 00:01:56,300
Before we save the user, we need to hash the user password before saving it here.

24
00:01:56,420 --> 00:02:02,780
So first step is that we need to create a salt so it's equal to a weight.

25
00:02:02,780 --> 00:02:06,680
And then the big crypt dot change salt.

26
00:02:06,830 --> 00:02:14,150
So we need this one with a combination with the plane password to be able to generate the random string

27
00:02:14,150 --> 00:02:15,230
of characters.

28
00:02:15,230 --> 00:02:18,350
And here we provide the number.

29
00:02:18,350 --> 00:02:25,580
So the higher the number, the more secure the salt is going to be, but the higher the number also

30
00:02:25,580 --> 00:02:28,070
is going to slow down your application.

31
00:02:28,070 --> 00:02:30,950
So the recommended number is ten.

32
00:02:31,340 --> 00:02:39,020
The next step is that we need to hash we're going to be as concerned and call this one as password hashed.

33
00:02:42,460 --> 00:02:52,180
Is equal to A weight and B grapes dot hash then pass in the plane password, which is this one.

34
00:02:52,180 --> 00:02:56,140
And then the sort we got, which is this one.

35
00:02:56,140 --> 00:03:02,230
So now we are going to save this one instead of the plane password and that is it.

36
00:03:02,230 --> 00:03:05,860
So let's go ahead and register a user.

37
00:03:05,890 --> 00:03:17,470
So here, register and let me change this one to John and going to be as John at gmail.com.

38
00:03:17,470 --> 00:03:18,850
And it's sent.

39
00:03:20,340 --> 00:03:27,660
You can see that the user has been registered, but instead of playing password, we are saving this

40
00:03:27,660 --> 00:03:30,090
random string of characters.

41
00:03:30,120 --> 00:03:32,610
So the question is, how can we log in?

42
00:03:32,640 --> 00:03:36,060
Are you going to memorize all these characters here?

43
00:03:36,090 --> 00:03:38,160
The answer is no.

44
00:03:38,310 --> 00:03:44,940
We are going to get back the main password by verifying this one.

45
00:03:44,940 --> 00:03:48,960
So let's see how we are going to look in in the next video.

