WEBVTT 00:00.890 --> 00:01.730 Welcome back. 00:02.460 --> 00:05.070 OK, I hope you tried to solve the exercise. 00:05.750 --> 00:10.650 Now I'm going to solve it without using the cool features of God that you didn't learn about yet. 00:10.820 --> 00:13.200 Normally, I would do this in a different way. 00:13.640 --> 00:17.600 However, at this level, it's better to use the features that you learned so far. 00:17.930 --> 00:18.410 All right. 00:18.410 --> 00:19.130 Let's get started. 00:21.470 --> 00:26.240 That's at the second username and password inside the constant declaration here. 00:27.330 --> 00:31.140 I'm going to add one more user, Konstanty user to. 00:33.400 --> 00:38.800 In lunch, then I'm going to add the password constant for a second user pass to. 00:40.400 --> 00:41.620 Eighty seven, nine. 00:42.050 --> 00:42.430 OK. 00:45.210 --> 00:51.660 In this if statement, I need to check the username of the second user like this, you not equals the 00:51.660 --> 00:52.320 user to. 00:52.590 --> 00:56.910 OK, so if what user names are not correct, then I will display another. 00:58.060 --> 01:00.950 Otherwise, it will execute this massive branch here. 01:01.780 --> 01:04.230 This means that both usernames are correct. 01:04.570 --> 01:09.190 So here I'm going to check whether the second password is also correct like this. 01:11.240 --> 01:13.970 Peanut equals to pasta here. 01:14.090 --> 01:18.730 I'm simply telling that don't grant access if both passwords are not correct. 01:19.720 --> 01:25.000 OK, let me try this first, I'm going to pass the username and the password for the second user. 01:26.190 --> 01:27.810 In 1879. 01:28.850 --> 01:29.750 Cool, it works. 01:30.000 --> 01:35.570 Now, let me try the first user's password instead, delete this and let's stop 1888. 01:37.560 --> 01:43.230 There's also works, right, but it shouldn't have worked, it's because now the second user can access 01:43.230 --> 01:45.900 to the system by using the first user's password. 01:46.740 --> 01:52.140 It's like you're accessing your email application, using another user's password, and they can also 01:52.140 --> 01:54.900 access yours by using their own password. 01:55.260 --> 01:56.380 So this is not good. 01:56.430 --> 01:57.750 Let's fix this now. 01:58.350 --> 02:00.570 OK, the problem is in this line. 02:02.100 --> 02:05.560 So it doesn't matter which user's password I'm passing to the program. 02:06.240 --> 02:12.080 It just checks whether the past password matches to the first users and the second user's password. 02:12.750 --> 02:13.710 So that's the problem. 02:14.310 --> 02:19.230 To solve this, I need to add another condition to this booth expression for now. 02:19.230 --> 02:21.180 Let's remove the second check from here. 02:22.710 --> 02:26.730 OK, so first I need to check for the first user like this. 02:27.890 --> 02:29.330 You equals to user. 02:32.660 --> 02:38.990 Then let's make this more simple by changing does not equal operator to equal operator like this. 02:40.430 --> 02:45.820 Since his last expression checks for the correct user and password, so I need to move this access, 02:45.860 --> 02:55.850 OK, from here to here, then I also need to move this air password from here to here, OK? 02:58.440 --> 03:04.770 So here first is checks for the first user, and if it's the first user, then it checks for it's password. 03:05.650 --> 03:11.890 So if the user is the first user and the password is the first user's password, then it grants access. 03:14.650 --> 03:17.590 Now, this at another check for the second user this time. 03:18.490 --> 03:23.710 First, I'm going to type a logical or operator, then in a new line, I'm going to check for the second 03:23.710 --> 03:25.270 username like this. 03:26.460 --> 03:31.350 And if it's correct, then I'm going to check for a second user's passwords like this. 03:32.940 --> 03:40.620 So here, if it's the first user and it's password is correct or if it's the second user or if it's 03:40.620 --> 03:43.910 password is correct, then the program will grant access. 03:44.610 --> 03:50.610 But if neither of them is true, then it will execute this as branch and it will say that the password 03:50.610 --> 03:51.480 is incorrect. 03:51.780 --> 03:58.170 OK, as you can see here, you and your line with an operator, then you can type the second expression 03:58.170 --> 03:58.980 just below it. 03:59.970 --> 04:04.500 OK, let's try this first, let's try it with the first user, Jack. 04:05.610 --> 04:12.900 Now, let's use the second user's password, 18 seven, and I call this time, it didn't grant access, 04:13.110 --> 04:16.380 as you can see now, I can't use the other users password. 04:17.570 --> 04:23.900 While security improvements indeed look now, this time the correct password for the first user. 04:26.680 --> 04:28.180 Access granted, cool. 04:29.370 --> 04:31.890 Now, let's do the same check for the second user. 04:33.850 --> 04:38.710 That the past the second user name with the first user's password, it shouldn't work. 04:38.830 --> 04:39.220 Right. 04:40.930 --> 04:42.940 All right, it didn't good. 04:44.080 --> 04:47.620 Now, this time, the correct password for the second user, finally. 04:48.570 --> 04:51.970 Access granted, good, OK, so far, so good. 04:52.470 --> 04:55.260 However, this court looks somewhat ugly, right? 04:55.860 --> 04:58.110 This bull condition looks complex to me. 04:58.630 --> 04:59.820 Let's make it simpler. 05:00.690 --> 05:03.660 I'm going to add another Assif branch here like this. 05:06.630 --> 05:09.300 Then I'm going to cut this bull exploration from here. 05:10.490 --> 05:15.170 Then I'm going to move it here as the condition for this elusive branch. 05:16.220 --> 05:19.440 And I need to remove this logical or Oprey there as well. 05:19.910 --> 05:24.740 And lastly, I need to duplicate the access granted message or the massive branch. 05:25.880 --> 05:31.790 OK, I think now it looks better, I needed to duplicate the access granted message, that's OK. 05:32.540 --> 05:36.580 Sometimes for more readable code, you may need to duplicate the code. 05:36.600 --> 05:43.400 OK, normally I could do this using a function that would not be duplicated, but you'll see how to 05:43.400 --> 05:44.450 do that afterwards. 05:45.560 --> 05:47.320 OK, let's try it one more time. 05:48.390 --> 05:49.770 That's right, a second user. 05:49.960 --> 05:53.160 The first user's password, again, he should, in fact. 05:54.170 --> 05:54.500 Good. 05:54.770 --> 05:56.670 It doesn't work now this time. 05:56.690 --> 05:58.820 That's correct, password for the second user. 06:00.590 --> 06:01.490 Access granted. 06:02.120 --> 06:06.440 OK, now let's pass the first user with the second user's password. 06:09.200 --> 06:11.310 Cool doesn't work either. 06:11.450 --> 06:13.700 Finally, this past the correct password. 06:15.920 --> 06:17.480 OK, access granted, cool. 06:18.790 --> 06:23.690 As you can see as of branch here, acts like a logical or operator, right? 06:24.310 --> 06:27.790 So this court and the previous court acts like the same. 06:29.420 --> 06:29.860 All right. 06:30.460 --> 06:37.370 So for now, you built a user password protected command line program, military level security indeed. 06:38.440 --> 06:40.180 I'm just kidding, of course. 06:40.770 --> 06:42.550 OK, you should be proud of yourself. 06:43.720 --> 06:45.870 Thank you for watching in the next hour.