Welcome to the final part of our assignment.
And that is to now create the actual authentication system
that will prompt the user to either register,
log in or maybe just even exit the system.
Now, what I'm going to do, first of all is I'm gonna remove the functions in here,
register and log in.
And I'm also going to remove the
while loop right here because we're going to run that in a different location.
And now I am going to
change the identation
and make sure that the
uh functions, register user and login user are on the same line.
This right here should be under
the Loginuser function and there it is. OK?
So
let us begin by creating the
authentication system. So I'm going to add my notes and call this one,
the main menu.
OK? And then we can define
are functioning here, authentication underscore system.
OK?
And there it is. All right. So what do we need here?
We need to prompt the user
to either register, log in or exit.
So we're going to print out a couple of statements. OK? So
let us begin by printing out
and I'm going to say
uh let's say basic authentication system.
Ok.
This will be at the very top.
And then next, let us print out the very first option for the user.
So we can say one dot
register
will be the first option,
ok?
And then print
option number two.
So this will be two dot log
in.
Ok. And then the final option in here
would be three and then that's let's call that one exit.
OK?
And there it is. So we've got our three options in here.
Now,
the user will have to
add either 12 or three.
So let us create a variable that will represent that particular option. So
I'm going to call this one option.
OK? So option is going to be equal to input.
And now let us ask the user
enter your choice.
OK?
So we're asking the user right now, hey, provide us with
what you want to do.
So we're gonna have to create the if else if scenario where
we'll check to see if the user chooses option one, which is register,
we can call the register user function.
If they choose option two, we can call the login user function or if they exit,
we can simply end the loop.
So
I am going to say right now
that
if
option
right here equals
and now I can say one
call on
what do we do if this choose
option one, well, we can call the function register underscore user.
OK? Very, very straightforward.
Now, LS F which is gonna be LF if it was option
two,
what are we gonna do?
We are going to call the function login underscore user.
And now
for the last one,
option
uh equals
three,
what do we do?
We can print
and then in code we can say, exiting the system.
OK?
And
there it is. And then we can say else
if the user
maybe provides option 456, which don't exist,
then we can say else print
and then in brackets, we can say
invalid choice.
And then we can say, please choose from
options
12 or three.
And there it is.
And now finally,
we can warn the authentication system,
we can do this by simply saying authentication system.
And there it is.
So
there is one thing
that we haven't added just yet. I don't know if you can spot what it is,
but that is the loop
because right now as it is, it will this program will run just once.
But we want the user to keep on either logging in or registering or exiting.
So what do we do?
This is where we will have to call in the while, while true loop.
But where do you think we're gonna put it?
We are going to put it just underneath
our authentication system function. OK? So
here is where I'm going to say while true.
And now remember everything in here
will have to fall under
the while true statement. So
make sure your identation is correct.
And then we're going to have to add the break statement as well to end the loop.
Now, where are we going to end the loop? We'll end the loop
where the user chooses option three, which is to exit the system.
So just underneath in here,
underneath print, I'm going to say break
and
there it is our program hopefully should work without any issues.
Let me go ahead right now and run it
and ok, so we do have
an issue right here
and that's because
the break. Oh, the break is outside the loop and look at that.
Oh, wow. I
indentation is so important. You can see right now that if all of this
is in the same indentation as the while statement. So
yeah, let us go back over here
and indent them properly and there it is, you can see even I,
I make mistakes with my identation as well.
So
let's make sure that everything else is indented properly.
Ok? All right. Let's try running the program one more time. Ok.
Thankfully, it works now. So
let us test it out case I'm gonna go with option number one. First of all,
let us register mark
and his password is admin
Awesome. Now let us try going to option number two
to log in.
Ok. So user name, let's try Nancy as an example password, let's say Bob.
But now it says invalid name, username, password. Please try again. So
it's obviously working really well. So let's try again to register
this time as Mac
once again and check to see if the program will detect that Mac already exists.
So Mark
and it says, ok, user
already exists. Please choose a different username. Ok.
Let us try logging in this time
as mark.
OK, analyst provide the password which is admin and it says, welcome back.
It actually worked.
Let us try to login in again as Mark.
But this time let us use a different password,
a long password and then it says invalid username and password.
Please try again.
So it appears it is working properly. The final test is to exit, enter
and there you go,
exit in the system. The loop has ended,
the program has ended. So there it is, we have successfully created
our program,
which is a basic authentication system
that would allow a user to either register log in or simply exit the program.
And of course,
we've added checks to ensure that no duplicate accounts can be registered.
We've also added checks to ensure that the usernames and passwords will match.
And there it is. Congratulations. I hope you enjoyed this assignment.
This challenge.
Thank you for watching. I will see you in the next class.