All right.
So welcome to the programming challenge where we are going to create for ourselves,
a very basic authentication system.
We're going to apply everything we've learned so far
from variables to functions to loops and of course,
most recently
dictionaries. All right,
now
I have already written out the program. This is the output. OK?
So the way the program is going to work is like this.
At the very beginning,
the user will be presented with three options to either register,
log in or simply exit the program.
Now, if they say three, it will immediately exit the program and will
end the entire
authentication system.
However,
if they were to go with one
and press enter
now, they will be asked to provide a username. I'm gonna go with John,
let me provide my password as password
and there you go. Registration will be successful.
Now, if I was to go and type in one again and I tried using the exact same username,
John to create a new account,
the system will check to see that oh John already exists. Try a different username.
So our program is going to check to see if the username already exists.
Now, for number two, if we try logging in, it's going to ask for the username.
Now, if I say John, all right, and then I provide the right password.
You can see right now, it's gonna say login successful. Welcome back.
Now, if I try logging in again with the exact same username, John,
but this time I used the obviously wrong password,
it's gonna say any valid username or password, Please try again.
So
this is going to be our basic authentication system.
This is how it is going to work.
And what I wanna do right now is to bring over my notepad file in here
just to kind of give you an idea of what we're going to
be working with. So
obviously,
we're going to need a dictionary that will store the
user credentials because we're gonna have to compare and see if
the new username
that the user wants to input has already been created before.
If the password is correct things like that.
And we're going to be using the dictionary because we'll have to create the pair,
the key value pair
using them and password where
username will be the key
and then the value of the key will be the password. So
dictionaries are going to be useful here.
We're going to need two different functions.
The very first function will be to register the user
and then the other will be to log in the user.
Now for the actual function to register the user. What do we need?
First of all, we are going to have to ask the user to provide their username
and then we'll have to have some sort of an if
else statement that will check to see if the username already exists
if it does ask for another username. However, if it's a brand new username,
then the program can proceed to ask for the password.
Once the user has provided both username and password,
we will then have to create
the username, password, key value. P I'm going to show you how exactly to do this.
Once this is done,
we can then say that the registration has been successful.
So pretty straightforward
for the function to log in the existing user again,
you will have to ask the user to provide their username and password.
And then we would have to check to see if the username matches the password
that's already been stored in the dictionary.
If it's false, then we're gonna print invalid username and password.
Otherwise, if it's true, if the password and username match,
then we can say login successful.
And then finally,
the third stage will be to create the actual authentication system
where the user will be presented with three
options to either register login or quit.
And depending on which option the user chooses,
we would have to call the relevant function.
So
we're gonna build this authentication system from the ground up. Are you excited?
I hope you are. Let's jump right in.