Welcome back. So now we need to implement
the password checker tool
so far. So good. Our users, they can register accounts, they can login,
but we want to make sure that the passwords that they use
to create their accounts in the first place is actually strong enough.
And we have a list of criteria. We
want to make sure that the password is at least eight characters.
It contains a capital letter,
it contains a number and it also contains at least one special symbol.
Now, the symbols are what I've written over here.
You can see I have all of them listed out.
So what I'm gonna do is at the very top. Ok. Let's go ahead and
let me just cut this. First of all, I'm going to cut that.
So we're gonna have to import a library which
is going to be the regular expressions library.
So
at the very top, let's say import and then re ok. So
let me just add a note
that says import for regular expressions.
OK.
All right. So now let us add
a note
and I will say a password,
password checker function.
OK? I think that's, that's fine
password checker
function.
Ok.
So
let us create the name of the function. So I'm gonna call it define and then
we can say is underscore strong
uh underscore password.
Ok.
How about that? And now, of course, inside
we're going to accept one variable which will be the actual password itself.
Ok.
And let's add a colon
and there you go. All right.
Let us begin to add the criteria.
The very first criteria here will be the length of the password. So
we can say if and now
the function L which represent the length of what of the password?
Ok. So if it is less,
then eight,
let's add our colon. What are we gonna say? We're gonna return false.
Ok. We're gonna return false,
actually, false capital F false comma.
And then we can provide something like a feedback
telling the user that, hey, your password must be at least eight characters long.
So let's do that. Ok.
So
notice right now two things that happened. First of all,
we are returning false, meaning that the password isn't strong enough.
And then we're also providing a feedback as well.
Keep that in mind. It's gonna be very, very important.
Let's move on to the next criteria.
So I'm gonna come down here
and then say if
and now not.
Ok.
R
search,
we want to search
using the R module. Let me just make sure I typed it correctly, search.
And now in brackets,
we want search to see if there are any uppercase letters within the string. Ok.
So we're saying we do search
and now are
ok.
And now
in code single codes,
let's add our brackets. What are we searching for?
We're searching for A to Z.
So this right here is a method
using the regular expressions library.
We want to search through our password to check to see
if there is any capital letter between A to Z.
So
A to Z
and then comma and then in password.
Ok.
So
we can return for false
and why false? Because we said if not.
So if the program such as through the password
and doesn't find a capital letter A to Z,
it's going to be not.
So we're going to return false and then we can provide what a feedback.
So I can say password
must
include,
include
at least
one upper case
uh letter.
Ok.
And let me add a dot Right there
and there you go. Ok.
Now, can you try to write the code to search
to see if a number between zero and nine is in the password? Ok.
We can say if not, we do search.
Ok. And then in brackets
R and now in single codes, I'm going to open up
a new bracket now between 0 to 1 to 9.
And now we're searching for the password.
We want to know if the password has a number between zero and nine
and of course, if it doesn't,
we're going to return false
and then we can say password must, must include at least one digit.
Let me change digits to number actually.
Ok.
And there you go.
So we've checked the length of the password.
We've checked to make sure it has an uppercase letter.
We've checked to make sure it has at least one number last but not least,
let us check to see if it has a special symbol.
So
the last one I'm gonna say, if not we dot Search
and now in brackets
are
singular codes. And now let's open up the main brackets
and now I am going to paste
all the special symbols.
Oh, there's quite a number of them actually. Ok. So I'm gonna add that
now comma and now password.
Ok.
Add a colon.
And now
if we don't have
that, I'm going to return
falls.
Ok. And then codes I will say password
uh, must include at least one special
symbol. Let me change
character, the symbol,
same
codes
and there it is. Ok.
So
we've checked
the four main criteria.
However,
what if the password that was created is actually good. It's a strong password. So
for that,
I'm gonna come over here
and I'm going to return. True.
Ok.
I'm going to return True. And we can even print out something that says password
is strong
and there you go.
So
just to give you a very quick recap of what we've done over here,
we imported the regular expressions library because we
want to use a particular method of function,
which is the search function
to go through the password and check for specific kinds of criteria. So first of all,
we check the length of the password.
Is it less than eight?
If it's less than eight,
we return false and then provide a feedback that
says password must be at least eight characters long.
And now we want to search to see if there is a capital letter between A to Z.
So we use the method re dot search
and then in brackets R codes and then the brackets A to Z
and then password.
And then we provide the feedback
and then we did the same to search for at least one number.
And then we did the same to search for at least one special symbol.
And then finally, if all four criteria were passed,
we will return true.
And then we would say password is strong.
So
now that we have the criteria listed out for the strength of the password,
we now need to integrate it within the registration function and and make sure
that before the user's account is registered,
the password actually passes the test.
So right here,
once we've asked the user to provide their username and the password, before
we begin opening up, the users do text file to store the credentials.
Let us introduce the password checkout. So
I can create a verbal code is valid.
Ok.
We're gonna check to see if the password is actually valid.
And then also
we've been working with what the feedback,
feedback or message you can change the variable if you, if you want to.
But I'm gonna go with feedback.
Ok.
So I'm gonna say is valid underscore feedback.
And I'm, I'm gonna pass them into the function that we used to create a
password which is what is strong
underscore password.
And then in Beckett's
password.
Ok.
So now
we can say if it's not valid, so if not
is valid.
So if the password they provided isn't strong enough, we can simply print
and then we can save
password is
not up too much space, password is not
strong enough.
Ok?
And then
what else can we do?
We can print the feedback
saying, hey,
your password needs at least one number or your
password must include at least one uppercase letter.
So
I can come down here,
add another print statement
and just simply pass in the feed back
and
there you go last but not least we are simply going to return
and
there you go.
So that is the way how we can implement
the password checker tool.
We've listed out the criteria
length
number, uppercase letter symbol
and now where you have the registration function
we've added, ok,
if the password isn't valid,
say it's not strong enough and then also provide the feedback as well,
otherwise simply return.
So now let's check to see if it's working. Hopefully it should. So let's run.
Ok, I'm going to register
username, let's say Bob uh password. I'm gonna go with capital letter San
6123
BV,
press enter and awesome. It says password is not strong enough.
Password must include at least one special symbol. Ok.
I'm gonna open up the users 0.60 file and make sure that.
Ok, make sure Bob wasn't created. Awesome.
Let's go back
and now let us try to create an actual real account.
So let's call Alice
password, pop
34
SDR and then the at symbol I think they should be strong enough.
There you go. Ok. Awesome. User is
so successful.
And now if I go back to my users dot TXT, there you go.
Now we have Alice and her password.
So congratulations. We have enhanced our program,
our software to now include a password checker as well.
Join me in the
next video where we're going to go ahead
and also learn how we can encrypt our passwords. I see you then.