1 00:00:00,300 --> 00:00:01,960 So the first thing we're going to do will be 2 00:00:01,970 --> 00:00:06,889 to create the function that will register the user. 3 00:00:07,280 --> 00:00:10,600 However, let us create a dictionary 4 00:00:10,789 --> 00:00:13,840 that will be used to store the user credentials. So 5 00:00:14,479 --> 00:00:18,840 for the dictionary, we can call it user underscore credentials. 6 00:00:19,770 --> 00:00:22,239 All right equals and then we're going to have our co 7 00:00:22,809 --> 00:00:23,909 braces. 8 00:00:24,629 --> 00:00:25,170 All right. 9 00:00:25,819 --> 00:00:29,459 Now for the actual function to register our user. 10 00:00:29,469 --> 00:00:34,720 In fact, let me just add the note there real quick. So function to register, 11 00:00:35,740 --> 00:00:36,880 use up. OK? 12 00:00:38,349 --> 00:00:39,450 Let's define 13 00:00:39,720 --> 00:00:41,220 the function. So I'm gonna go 14 00:00:41,430 --> 00:00:41,500 there 15 00:00:41,770 --> 00:00:45,169 and then let's say register underscore user. 16 00:00:45,900 --> 00:00:47,520 OK? Colon. 17 00:00:48,139 --> 00:00:54,840 Now what do we need? First of all, we need to ask the user to input the user name 18 00:00:55,090 --> 00:01:00,590 and we can assign that to a variable, let's call that variable username 19 00:01:00,970 --> 00:01:02,130 equals. 20 00:01:02,459 --> 00:01:07,080 And now let us prompt the user to provide the username. So input 21 00:01:07,529 --> 00:01:10,440 and then we can say enter 22 00:01:11,540 --> 00:01:13,680 your username. 23 00:01:14,930 --> 00:01:16,750 OK? Just as an example, 24 00:01:17,610 --> 00:01:18,910 let's press enter 25 00:01:19,709 --> 00:01:23,089 and let me leave some space in here between the colon and the 26 00:01:23,940 --> 00:01:26,019 our code to have some space in. 27 00:01:26,440 --> 00:01:26,959 So 28 00:01:27,269 --> 00:01:29,690 right now we need to check to see if 29 00:01:29,699 --> 00:01:33,980 the username that the user provides actually already exists. 30 00:01:34,180 --> 00:01:37,470 So let me just add a note in here on a separate line. 31 00:01:37,889 --> 00:01:39,959 Let's add the notes, 32 00:01:40,269 --> 00:01:42,470 check to see if username 33 00:01:42,690 --> 00:01:43,800 already 34 00:01:44,550 --> 00:01:45,639 exists. 35 00:01:46,250 --> 00:01:49,650 OK? So how are we going to do this? Well, we can do so 36 00:01:49,940 --> 00:01:55,169 by using the if statement. So I'm gonna say if username and now in 37 00:01:55,839 --> 00:01:57,459 the user credentials 38 00:01:58,160 --> 00:02:01,459 again, Python has already given us the code. 39 00:02:01,599 --> 00:02:05,819 So if username in the user credentials call on, 40 00:02:05,830 --> 00:02:13,020 let us print username already exists, please choose a different username. 41 00:02:13,360 --> 00:02:18,080 I think I like this. However, I'm going to remove the return, we don't need that. 42 00:02:18,389 --> 00:02:18,899 So, 43 00:02:19,669 --> 00:02:21,169 however, if the username 44 00:02:21,539 --> 00:02:26,679 doesn't exist, if it's a brand new username, we can then add our else. 45 00:02:27,110 --> 00:02:32,130 What else do we now need to do? We need to ask the user for their password, right? So 46 00:02:32,399 --> 00:02:33,550 I'm gonna say let 47 00:02:34,380 --> 00:02:36,449 us create a variable password 48 00:02:37,070 --> 00:02:39,490 and then assign that to the inputs, 49 00:02:39,779 --> 00:02:41,880 inputs and then in brackets, 50 00:02:42,460 --> 00:02:43,720 let's say, 51 00:02:45,779 --> 00:02:47,449 enter a 52 00:02:47,820 --> 00:02:48,960 password 53 00:02:50,699 --> 00:02:53,160 call on and then let's add the closing coats 54 00:02:53,970 --> 00:02:55,320 and there it is. Ok. 55 00:02:55,550 --> 00:02:57,350 So from here right now, 56 00:02:57,729 --> 00:03:00,229 the next step that we'll have to do 57 00:03:00,589 --> 00:03:02,210 is to create 58 00:03:02,330 --> 00:03:04,509 the key value pair 59 00:03:04,619 --> 00:03:09,669 for username and password. Now, how are we going to do this? 60 00:03:09,839 --> 00:03:11,350 Well, we're going to do so 61 00:03:11,669 --> 00:03:15,429 by calling the dictionary user credentials. 62 00:03:16,399 --> 00:03:19,779 Ok. And now check this out. I'm gonna open up my brackets 63 00:03:20,110 --> 00:03:23,619 and I'm going to provide the key which will be username 64 00:03:24,460 --> 00:03:28,160 and now equals to password. 65 00:03:28,419 --> 00:03:31,479 This is how we can create 66 00:03:31,860 --> 00:03:34,139 the key value pair. 67 00:03:34,339 --> 00:03:37,039 You provide the name of the dictionary and then in brackets, 68 00:03:37,050 --> 00:03:41,460 you provide the name of the key equals to its value 69 00:03:41,710 --> 00:03:48,350 and there it is right there. And then the final step will now be to simply print 70 00:03:48,669 --> 00:03:49,800 registration 71 00:03:50,009 --> 00:03:51,199 successful 72 00:03:51,729 --> 00:03:52,710 and there it is. 73 00:03:53,039 --> 00:03:53,520 OK. 74 00:03:54,139 --> 00:03:58,660 Now let us try something. I am going to call this function 75 00:03:59,000 --> 00:04:01,880 and let's see if it actually works. I'm going to say register user 76 00:04:02,199 --> 00:04:03,360 brackets 77 00:04:03,759 --> 00:04:04,600 colon 78 00:04:05,059 --> 00:04:06,320 and there it is. Ok. 79 00:04:06,610 --> 00:04:09,279 Let us try this. 80 00:04:10,149 --> 00:04:13,259 Oh, so we don't need columns in here. I do apologize. We don't need colons there. 81 00:04:13,399 --> 00:04:14,919 Let's run the program 82 00:04:15,139 --> 00:04:16,760 all enter user name. 83 00:04:17,010 --> 00:04:18,709 I'm going to say John, 84 00:04:18,829 --> 00:04:23,029 let's enter a password. Let's just say John, ok, for the password. 85 00:04:23,309 --> 00:04:24,410 Uh John 86 00:04:24,779 --> 00:04:28,070 enter once again and it says registration successful. 87 00:04:28,230 --> 00:04:29,019 Ok. 88 00:04:29,390 --> 00:04:33,160 However, notice that the program has ended 89 00:04:33,269 --> 00:04:35,720 and that's because we don't have an actual loop 90 00:04:36,410 --> 00:04:41,019 that will continually run to keep asking the user to provide a new username, 91 00:04:41,029 --> 00:04:41,769 a new password. 92 00:04:41,779 --> 00:04:42,149 So 93 00:04:42,320 --> 00:04:44,149 what can we do to 94 00:04:44,459 --> 00:04:46,829 run this program indefinitely? Well, 95 00:04:47,019 --> 00:04:51,779 we can introduce the while true loop. So over here 96 00:04:52,019 --> 00:04:54,750 just underneath the register user function, 97 00:04:55,279 --> 00:04:58,410 I am not going to call in a loop that says Y 98 00:04:58,920 --> 00:05:00,179 and then true. 99 00:05:00,559 --> 00:05:04,709 However, indentation is going to be very, very important. So 100 00:05:05,160 --> 00:05:07,739 I am going to tab all of this 101 00:05:07,980 --> 00:05:12,739 to make sure that everything falls under the while true statement loop. 102 00:05:12,750 --> 00:05:14,220 Let me add my colon right there 103 00:05:14,619 --> 00:05:19,690 and there it is. Now we're going to have the program running continuously. 104 00:05:19,700 --> 00:05:22,359 And let's check to see if it will actually 105 00:05:22,369 --> 00:05:25,640 check if the username we provided already exists. 106 00:05:25,649 --> 00:05:26,100 So 107 00:05:26,299 --> 00:05:27,940 let's run the program again. 108 00:05:28,119 --> 00:05:29,140 All right. So 109 00:05:29,410 --> 00:05:34,339 this time I'm, I'm gonna go with mark. Uh, password is password. 110 00:05:34,839 --> 00:05:36,019 Ok. Fine, 111 00:05:36,390 --> 00:05:38,440 successful. Now, you can see it's asking 112 00:05:38,690 --> 00:05:40,019 for another username. 113 00:05:40,179 --> 00:05:45,619 Let's try uh Nancy password. Let's go with sword fish. 114 00:05:45,779 --> 00:05:50,529 Ok. It's working. Now, let us try using Mara 115 00:05:50,630 --> 00:05:52,109 enter 116 00:05:52,410 --> 00:05:57,040 and now it says uh oh, username already exists. Please choose a different username. 117 00:05:57,049 --> 00:06:00,859 So awesome. We can see right now that the first part of our program, 118 00:06:01,010 --> 00:06:03,130 the one that checks to see if 119 00:06:03,489 --> 00:06:06,790 or the one that registers user and checks to see if the username already exists. 120 00:06:06,799 --> 00:06:09,010 You can see right now that it's working perfectly fine 121 00:06:09,190 --> 00:06:10,510 and that is awesome. So 122 00:06:10,700 --> 00:06:13,109 join me in the next video where we're now going to move on to 123 00:06:13,119 --> 00:06:18,410 stage two where we're going to create the function to log in the user.