1 00:00:00,239 --> 00:00:03,359 Welcome to the final part of our assignment. 2 00:00:03,369 --> 00:00:07,050 And that is to now create the actual authentication system 3 00:00:07,309 --> 00:00:10,420 that will prompt the user to either register, 4 00:00:10,430 --> 00:00:13,819 log in or maybe just even exit the system. 5 00:00:14,270 --> 00:00:18,250 Now, what I'm going to do, first of all is I'm gonna remove the functions in here, 6 00:00:18,260 --> 00:00:19,860 register and log in. 7 00:00:20,340 --> 00:00:22,500 And I'm also going to remove the 8 00:00:22,979 --> 00:00:27,659 while loop right here because we're going to run that in a different location. 9 00:00:28,209 --> 00:00:30,729 And now I am going to 10 00:00:31,659 --> 00:00:33,240 change the identation 11 00:00:33,889 --> 00:00:35,990 and make sure that the 12 00:00:36,799 --> 00:00:41,220 uh functions, register user and login user are on the same line. 13 00:00:41,509 --> 00:00:44,540 This right here should be under 14 00:00:45,169 --> 00:00:47,560 the Loginuser function and there it is. OK? 15 00:00:47,860 --> 00:00:48,470 So 16 00:00:48,779 --> 00:00:52,060 let us begin by creating the 17 00:00:52,560 --> 00:00:55,810 authentication system. So I'm going to add my notes and call this one, 18 00:00:56,150 --> 00:00:57,540 the main menu. 19 00:00:58,380 --> 00:01:00,069 OK? And then we can define 20 00:01:01,290 --> 00:01:05,489 are functioning here, authentication underscore system. 21 00:01:06,059 --> 00:01:06,779 OK? 22 00:01:08,330 --> 00:01:12,309 And there it is. All right. So what do we need here? 23 00:01:12,680 --> 00:01:15,949 We need to prompt the user 24 00:01:16,209 --> 00:01:19,760 to either register, log in or exit. 25 00:01:19,769 --> 00:01:22,589 So we're going to print out a couple of statements. OK? So 26 00:01:22,830 --> 00:01:24,830 let us begin by printing out 27 00:01:25,269 --> 00:01:26,459 and I'm going to say 28 00:01:27,080 --> 00:01:32,660 uh let's say basic authentication system. 29 00:01:33,110 --> 00:01:33,889 Ok. 30 00:01:34,059 --> 00:01:35,809 This will be at the very top. 31 00:01:36,089 --> 00:01:40,699 And then next, let us print out the very first option for the user. 32 00:01:41,330 --> 00:01:43,059 So we can say one dot 33 00:01:43,309 --> 00:01:44,580 register 34 00:01:45,379 --> 00:01:47,319 will be the first option, 35 00:01:48,160 --> 00:01:48,870 ok? 36 00:01:49,239 --> 00:01:50,730 And then print 37 00:01:51,169 --> 00:01:52,419 option number two. 38 00:01:53,500 --> 00:01:56,379 So this will be two dot log 39 00:01:56,510 --> 00:01:57,089 in. 40 00:01:58,000 --> 00:02:01,059 Ok. And then the final option in here 41 00:02:01,580 --> 00:02:06,569 would be three and then that's let's call that one exit. 42 00:02:06,830 --> 00:02:07,449 OK? 43 00:02:08,038 --> 00:02:10,699 And there it is. So we've got our three options in here. 44 00:02:11,350 --> 00:02:12,110 Now, 45 00:02:12,529 --> 00:02:14,160 the user will have to 46 00:02:14,759 --> 00:02:16,500 add either 12 or three. 47 00:02:16,509 --> 00:02:22,740 So let us create a variable that will represent that particular option. So 48 00:02:23,059 --> 00:02:25,979 I'm going to call this one option. 49 00:02:26,350 --> 00:02:30,020 OK? So option is going to be equal to input. 50 00:02:30,639 --> 00:02:33,419 And now let us ask the user 51 00:02:34,490 --> 00:02:36,949 enter your choice. 52 00:02:37,839 --> 00:02:38,690 OK? 53 00:02:38,910 --> 00:02:41,660 So we're asking the user right now, hey, provide us with 54 00:02:41,820 --> 00:02:43,300 what you want to do. 55 00:02:43,550 --> 00:02:49,210 So we're gonna have to create the if else if scenario where 56 00:02:49,860 --> 00:02:53,410 we'll check to see if the user chooses option one, which is register, 57 00:02:53,539 --> 00:02:55,880 we can call the register user function. 58 00:02:55,889 --> 00:03:01,509 If they choose option two, we can call the login user function or if they exit, 59 00:03:01,520 --> 00:03:03,630 we can simply end the loop. 60 00:03:03,639 --> 00:03:04,050 So 61 00:03:04,320 --> 00:03:06,000 I am going to say right now 62 00:03:06,279 --> 00:03:07,160 that 63 00:03:08,399 --> 00:03:09,100 if 64 00:03:10,470 --> 00:03:11,570 option 65 00:03:11,699 --> 00:03:13,509 right here equals 66 00:03:13,940 --> 00:03:16,130 and now I can say one 67 00:03:16,970 --> 00:03:17,809 call on 68 00:03:18,039 --> 00:03:19,500 what do we do if this choose 69 00:03:19,720 --> 00:03:25,029 option one, well, we can call the function register underscore user. 70 00:03:25,750 --> 00:03:27,690 OK? Very, very straightforward. 71 00:03:27,889 --> 00:03:33,210 Now, LS F which is gonna be LF if it was option 72 00:03:34,139 --> 00:03:34,850 two, 73 00:03:36,809 --> 00:03:37,910 what are we gonna do? 74 00:03:38,289 --> 00:03:43,669 We are going to call the function login underscore user. 75 00:03:44,389 --> 00:03:45,210 And now 76 00:03:45,350 --> 00:03:46,649 for the last one, 77 00:03:48,929 --> 00:03:49,330 option 78 00:03:51,250 --> 00:03:52,949 uh equals 79 00:03:54,960 --> 00:03:56,020 three, 80 00:03:57,759 --> 00:03:59,050 what do we do? 81 00:03:59,380 --> 00:04:00,820 We can print 82 00:04:02,440 --> 00:04:07,580 and then in code we can say, exiting the system. 83 00:04:08,270 --> 00:04:09,089 OK? 84 00:04:09,580 --> 00:04:10,289 And 85 00:04:10,589 --> 00:04:14,130 there it is. And then we can say else 86 00:04:15,440 --> 00:04:16,619 if the user 87 00:04:16,890 --> 00:04:20,178 maybe provides option 456, which don't exist, 88 00:04:20,369 --> 00:04:22,779 then we can say else print 89 00:04:23,149 --> 00:04:24,739 and then in brackets, we can say 90 00:04:25,269 --> 00:04:27,579 invalid choice. 91 00:04:27,899 --> 00:04:30,619 And then we can say, please choose from 92 00:04:30,940 --> 00:04:32,850 options 93 00:04:33,380 --> 00:04:36,540 12 or three. 94 00:04:37,369 --> 00:04:38,269 And there it is. 95 00:04:39,399 --> 00:04:41,019 And there it is. 96 00:04:41,160 --> 00:04:42,459 And now finally, 97 00:04:43,450 --> 00:04:46,510 we can warn the authentication system, 98 00:04:47,700 --> 00:04:50,519 we can do this by simply saying authentication system. 99 00:04:51,170 --> 00:04:52,790 And there it is. 100 00:04:53,070 --> 00:04:53,700 So 101 00:04:53,950 --> 00:04:56,269 there is one thing 102 00:04:56,690 --> 00:05:01,230 that we haven't added just yet. I don't know if you can spot what it is, 103 00:05:01,880 --> 00:05:04,019 but that is the loop 104 00:05:04,339 --> 00:05:08,359 because right now as it is, it will this program will run just once. 105 00:05:08,369 --> 00:05:13,160 But we want the user to keep on either logging in or registering or exiting. 106 00:05:13,170 --> 00:05:15,019 So what do we do? 107 00:05:15,540 --> 00:05:21,100 This is where we will have to call in the while, while true loop. 108 00:05:21,119 --> 00:05:22,850 But where do you think we're gonna put it? 109 00:05:23,299 --> 00:05:26,500 We are going to put it just underneath 110 00:05:26,910 --> 00:05:30,739 our authentication system function. OK? So 111 00:05:31,250 --> 00:05:33,989 here is where I'm going to say while true. 112 00:05:35,019 --> 00:05:37,239 And now remember everything in here 113 00:05:37,549 --> 00:05:39,559 will have to fall under 114 00:05:40,440 --> 00:05:42,220 the while true statement. So 115 00:05:43,750 --> 00:05:46,529 make sure your identation is correct. 116 00:05:46,859 --> 00:05:53,609 And then we're going to have to add the break statement as well to end the loop. 117 00:05:53,630 --> 00:05:56,869 Now, where are we going to end the loop? We'll end the loop 118 00:05:56,970 --> 00:06:00,399 where the user chooses option three, which is to exit the system. 119 00:06:00,410 --> 00:06:01,970 So just underneath in here, 120 00:06:02,579 --> 00:06:05,489 underneath print, I'm going to say break 121 00:06:05,679 --> 00:06:06,320 and 122 00:06:06,540 --> 00:06:11,869 there it is our program hopefully should work without any issues. 123 00:06:12,000 --> 00:06:14,510 Let me go ahead right now and run it 124 00:06:14,970 --> 00:06:17,869 and ok, so we do have 125 00:06:18,269 --> 00:06:19,470 an issue right here 126 00:06:19,660 --> 00:06:20,720 and that's because 127 00:06:21,010 --> 00:06:24,600 the break. Oh, the break is outside the loop and look at that. 128 00:06:25,350 --> 00:06:26,070 Oh, wow. I 129 00:06:26,339 --> 00:06:30,880 indentation is so important. You can see right now that if all of this 130 00:06:30,980 --> 00:06:35,059 is in the same indentation as the while statement. So 131 00:06:35,329 --> 00:06:37,720 yeah, let us go back over here 132 00:06:38,260 --> 00:06:42,529 and indent them properly and there it is, you can see even I, 133 00:06:42,549 --> 00:06:45,450 I make mistakes with my identation as well. 134 00:06:45,459 --> 00:06:45,760 So 135 00:06:46,070 --> 00:06:50,040 let's make sure that everything else is indented properly. 136 00:06:50,510 --> 00:06:54,130 Ok? All right. Let's try running the program one more time. Ok. 137 00:06:54,140 --> 00:06:55,929 Thankfully, it works now. So 138 00:06:56,079 --> 00:06:59,690 let us test it out case I'm gonna go with option number one. First of all, 139 00:06:59,799 --> 00:07:01,899 let us register mark 140 00:07:02,119 --> 00:07:03,890 and his password is admin 141 00:07:04,179 --> 00:07:08,410 Awesome. Now let us try going to option number two 142 00:07:08,649 --> 00:07:09,880 to log in. 143 00:07:10,489 --> 00:07:17,489 Ok. So user name, let's try Nancy as an example password, let's say Bob. 144 00:07:17,820 --> 00:07:21,890 But now it says invalid name, username, password. Please try again. So 145 00:07:22,049 --> 00:07:26,959 it's obviously working really well. So let's try again to register 146 00:07:27,299 --> 00:07:29,100 this time as Mac 147 00:07:29,380 --> 00:07:33,859 once again and check to see if the program will detect that Mac already exists. 148 00:07:33,869 --> 00:07:34,809 So Mark 149 00:07:35,029 --> 00:07:36,019 and it says, ok, user 150 00:07:36,130 --> 00:07:38,670 already exists. Please choose a different username. Ok. 151 00:07:39,390 --> 00:07:41,209 Let us try logging in this time 152 00:07:41,920 --> 00:07:43,119 as mark. 153 00:07:43,410 --> 00:07:47,459 OK, analyst provide the password which is admin and it says, welcome back. 154 00:07:47,470 --> 00:07:48,619 It actually worked. 155 00:07:48,750 --> 00:07:51,829 Let us try to login in again as Mark. 156 00:07:51,839 --> 00:07:54,190 But this time let us use a different password, 157 00:07:54,200 --> 00:07:57,269 a long password and then it says invalid username and password. 158 00:07:57,279 --> 00:07:58,299 Please try again. 159 00:07:58,450 --> 00:08:03,779 So it appears it is working properly. The final test is to exit, enter 160 00:08:04,190 --> 00:08:04,899 and there you go, 161 00:08:05,459 --> 00:08:07,559 exit in the system. The loop has ended, 162 00:08:07,690 --> 00:08:13,160 the program has ended. So there it is, we have successfully created 163 00:08:13,510 --> 00:08:14,880 our program, 164 00:08:15,420 --> 00:08:18,790 which is a basic authentication system 165 00:08:18,950 --> 00:08:23,850 that would allow a user to either register log in or simply exit the program. 166 00:08:23,959 --> 00:08:24,500 And of course, 167 00:08:24,510 --> 00:08:29,339 we've added checks to ensure that no duplicate accounts can be registered. 168 00:08:29,600 --> 00:08:33,590 We've also added checks to ensure that the usernames and passwords will match. 169 00:08:33,890 --> 00:08:38,558 And there it is. Congratulations. I hope you enjoyed this assignment. 170 00:08:38,570 --> 00:08:39,640 This challenge. 171 00:08:39,799 --> 00:08:42,400 Thank you for watching. I will see you in the next class.