We're getting so close, I can almost see the finish line.
So hanging in there.
We now have the hash and the count so we can finalize this function of get password leaks scanned in
here as we're looping through each item.
What do we want to check?
Well, we want to check that if the hash that is the tale of the hash here.
Is equal to hash.
To check, remember, hash.
To check is the tail end of our hash password that we never sent to anybody that is on our own machine.
So it's nice and secure.
And we're going to check this because the API returned us a list of these tailed hashes.
So if that matches well, in that case, I want you to return the count.
So I want to return how many times this password has been leaked?
Otherwise just return.
Zero.
Again, I can do this because it's going to exit out of this loop whenever it sees the return keyword.
Now in my pwned API check, I'm going to run this function which intel is going to grab all this information
and return the count of the times that the hashed password has been leaked.
So we have one last thing to do.
That is the ability to actually print out the result of all these calculations.
So let's remove this for now and create a main function.
And this main function is going to receive the arguments that we give it right in here in our command
line.
So we're going to import, as you might have seen before, the CIS module.
And in here, we're going to have a main function that receives the arguments, which is the passwords
that we want to check.
And for now, we'll just pass here.
But at the bottom, we're going to call the main function.
With the CIS dot RV and accept any number of arguments after we do the python three check my past up
pi and then we give it all the arguments that we want, which are the passwords.
So we're going to run the function like this.
This main function.
All it's going to do is we're going to say for password in the arguments because we can give it multiple
passwords.
We're going to loop through that.
And we're going to have a sha one password.
And a count, or we'll just do the count because we're going to receive the count from the get password
leaks count.
So we can do that by just doing pwned api check.
And we'll pass it the password that we're checking.
And all we're going to do is actually inside of this block, say if count exists in that case, I want
you to print an F string and this F string is going to say.
The.
Password that we're looping through.
Was found.
The count of how many times?
And then we'll say, you should probably change.
Your password.
Otherwise.
If that means there's no count, that is there are no matches, then you're all good.
We can say.
If string.
Password.
Was not found.
Carry on.
So that's a good password.
You should carry on.
You're all good.
And then finally, just for fun, let's return out of this function.
Return?
Done just like that.
If I save this, let's see what this gives us.
I'm going to say Python three.
Check my pass and let's just check.
Hello?
I get.
Hello.
Was not fun to carry on, but we know that hello was found before.
Right.
I mean, that's a simple password.
We should actually get something good here.
Now, I also want to remove this response of print.
Since we don't need it anymore, can you spot the error?
Again, this is a bit of a tricky part with Python, right?
It's the indentation and something that we've seen before.
So you want to get good at debugging your own code and figuring out what happens in this case, we can
go step by step through the code, but we can think, Hmm, we actually never tested this count function.
And if we look over here, our indentation is a little bit off, right?
We have the if check, but then we always return zero.
This returns should be like this after the for loop.
After we've checked everything, nothing has been matched.
Then we should return zero.
So if I save and run this again.
All right, now it's working.
You notice that's one simple slight error can give you completely different results.
So it's always good to go step by step and try out something with something that you already know works.
And it's also important to use your debugging skills that you'll develop throughout the course to try
and figure things out.
Now, no programmer is going to write a perfect program right out of the bat.
Most of the time you're trying to figure out why you're getting this error, why this is happening,
and this is just something that you become better and better at as you code.
So the only cure to this is to just keep coding.
Hopefully throughout the course you've seen some of the errors that I make in how I debug them so that
you start to adopt these patterns as well.
Anyway, this is awesome.
This is finally working.
Let's try a couple more things.
Let's say bye and then some gibberish.
All right.
Looks like this is working as well.
This is awesome.
Our password checker is working.
Now, I want to do one more thing here.
To finish out this project.
So let's do that in the next video.