1 00:00:00,469 --> 00:00:00,889 All right. 2 00:00:00,899 --> 00:00:06,789 So welcome to the programming challenge where we are going to create for ourselves, 3 00:00:07,139 --> 00:00:10,779 a very basic authentication system. 4 00:00:11,010 --> 00:00:13,750 We're going to apply everything we've learned so far 5 00:00:13,760 --> 00:00:17,680 from variables to functions to loops and of course, 6 00:00:17,690 --> 00:00:18,860 most recently 7 00:00:19,079 --> 00:00:20,489 dictionaries. All right, 8 00:00:20,860 --> 00:00:21,540 now 9 00:00:21,940 --> 00:00:25,389 I have already written out the program. This is the output. OK? 10 00:00:25,399 --> 00:00:28,149 So the way the program is going to work is like this. 11 00:00:28,549 --> 00:00:29,559 At the very beginning, 12 00:00:29,569 --> 00:00:33,569 the user will be presented with three options to either register, 13 00:00:33,580 --> 00:00:36,529 log in or simply exit the program. 14 00:00:36,840 --> 00:00:41,569 Now, if they say three, it will immediately exit the program and will 15 00:00:41,729 --> 00:00:43,889 end the entire 16 00:00:44,380 --> 00:00:45,610 authentication system. 17 00:00:46,009 --> 00:00:46,889 However, 18 00:00:47,259 --> 00:00:49,090 if they were to go with one 19 00:00:49,389 --> 00:00:50,500 and press enter 20 00:00:50,729 --> 00:00:54,400 now, they will be asked to provide a username. I'm gonna go with John, 21 00:00:54,779 --> 00:00:57,970 let me provide my password as password 22 00:00:58,840 --> 00:01:01,220 and there you go. Registration will be successful. 23 00:01:01,409 --> 00:01:06,510 Now, if I was to go and type in one again and I tried using the exact same username, 24 00:01:06,519 --> 00:01:08,580 John to create a new account, 25 00:01:08,839 --> 00:01:14,099 the system will check to see that oh John already exists. Try a different username. 26 00:01:14,400 --> 00:01:19,690 So our program is going to check to see if the username already exists. 27 00:01:19,970 --> 00:01:25,379 Now, for number two, if we try logging in, it's going to ask for the username. 28 00:01:25,730 --> 00:01:30,269 Now, if I say John, all right, and then I provide the right password. 29 00:01:30,480 --> 00:01:34,019 You can see right now, it's gonna say login successful. Welcome back. 30 00:01:34,139 --> 00:01:37,559 Now, if I try logging in again with the exact same username, John, 31 00:01:37,720 --> 00:01:40,860 but this time I used the obviously wrong password, 32 00:01:41,010 --> 00:01:44,750 it's gonna say any valid username or password, Please try again. 33 00:01:45,029 --> 00:01:45,639 So 34 00:01:45,750 --> 00:01:49,830 this is going to be our basic authentication system. 35 00:01:49,940 --> 00:01:51,870 This is how it is going to work. 36 00:01:52,260 --> 00:01:58,209 And what I wanna do right now is to bring over my notepad file in here 37 00:01:58,889 --> 00:02:01,930 just to kind of give you an idea of what we're going to 38 00:02:02,339 --> 00:02:04,419 be working with. So 39 00:02:05,290 --> 00:02:05,989 obviously, 40 00:02:06,000 --> 00:02:09,410 we're going to need a dictionary that will store the 41 00:02:09,419 --> 00:02:12,669 user credentials because we're gonna have to compare and see if 42 00:02:12,869 --> 00:02:14,350 the new username 43 00:02:14,490 --> 00:02:17,669 that the user wants to input has already been created before. 44 00:02:17,899 --> 00:02:19,779 If the password is correct things like that. 45 00:02:20,080 --> 00:02:23,779 And we're going to be using the dictionary because we'll have to create the pair, 46 00:02:23,789 --> 00:02:25,470 the key value pair 47 00:02:25,720 --> 00:02:27,149 using them and password where 48 00:02:27,320 --> 00:02:28,789 username will be the key 49 00:02:29,130 --> 00:02:33,190 and then the value of the key will be the password. So 50 00:02:33,330 --> 00:02:36,229 dictionaries are going to be useful here. 51 00:02:36,570 --> 00:02:38,649 We're going to need two different functions. 52 00:02:38,660 --> 00:02:41,729 The very first function will be to register the user 53 00:02:41,899 --> 00:02:45,250 and then the other will be to log in the user. 54 00:02:45,500 --> 00:02:49,429 Now for the actual function to register the user. What do we need? 55 00:02:49,440 --> 00:02:54,710 First of all, we are going to have to ask the user to provide their username 56 00:02:55,139 --> 00:02:57,229 and then we'll have to have some sort of an if 57 00:02:57,240 --> 00:03:01,130 else statement that will check to see if the username already exists 58 00:03:01,289 --> 00:03:06,869 if it does ask for another username. However, if it's a brand new username, 59 00:03:07,029 --> 00:03:09,880 then the program can proceed to ask for the password. 60 00:03:10,289 --> 00:03:13,679 Once the user has provided both username and password, 61 00:03:13,929 --> 00:03:16,080 we will then have to create 62 00:03:16,300 --> 00:03:21,160 the username, password, key value. P I'm going to show you how exactly to do this. 63 00:03:21,509 --> 00:03:22,970 Once this is done, 64 00:03:23,119 --> 00:03:26,460 we can then say that the registration has been successful. 65 00:03:26,470 --> 00:03:27,960 So pretty straightforward 66 00:03:28,470 --> 00:03:31,309 for the function to log in the existing user again, 67 00:03:31,320 --> 00:03:34,789 you will have to ask the user to provide their username and password. 68 00:03:35,089 --> 00:03:41,550 And then we would have to check to see if the username matches the password 69 00:03:42,320 --> 00:03:44,440 that's already been stored in the dictionary. 70 00:03:44,509 --> 00:03:48,380 If it's false, then we're gonna print invalid username and password. 71 00:03:48,449 --> 00:03:52,339 Otherwise, if it's true, if the password and username match, 72 00:03:52,369 --> 00:03:54,850 then we can say login successful. 73 00:03:55,089 --> 00:03:56,110 And then finally, 74 00:03:56,119 --> 00:04:00,619 the third stage will be to create the actual authentication system 75 00:04:00,860 --> 00:04:03,149 where the user will be presented with three 76 00:04:03,160 --> 00:04:06,990 options to either register login or quit. 77 00:04:07,169 --> 00:04:09,949 And depending on which option the user chooses, 78 00:04:10,009 --> 00:04:13,250 we would have to call the relevant function. 79 00:04:13,720 --> 00:04:14,240 So 80 00:04:15,039 --> 00:04:20,320 we're gonna build this authentication system from the ground up. Are you excited? 81 00:04:20,329 --> 00:04:22,100 I hope you are. Let's jump right in.