Welcome back.
Let's continue building our awesome tool.
We have our pond API check that only converts our password to SHA one.
But we need to send this to the API.
The password API.
So what can we do here?
The first thing we want to do is remember we only need the first five characters of our password or
the hashed password so we can do something fun here.
We can say first five characters.
And also have what we call the tail.
So we're going to store the first five characters and the first variable.
And in the second variable we're going to store the remaining because we're going to need both of these
later on.
So in here.
We can just use the nifty little thing that, well, Python allows us, which is this nice little syntax
to just grab the start up to the fifth character.
And then for the second part.
The remaining characters.
So starting from the fifth index all the way till the end, nice and easy.
And this is something that we've learned about before.
So now we have the first five characters and the tail.
And here we can now add this to our request API data so I can now call my request API data and in here
give it well the first five characters and let's just store the response in here.
Like so.
Now let's see what type of response we get.
So I'm actually going to return response here.
And just so we make sure that we're doing everything right, let's print out the first five characters
and the tail as well to make sure that everything is working.
If I run this.
All right.
It looks like I'm getting the first five characters.
There's a space here, and then the remaining, and we don't get any error.
It looks like the response is working, so let's also print the response.
And make sure that that is working as well.
Looks like we get a response of 200, but we're still not sure exactly what type of data we receive.
What can we do here?
Well, I want to learn more about this data that we return.
So let's create another function here.
And for now, we'll just call it read response.
And we're going to just give it the response that we get.
And in here, let's just try to read this response.
We can actually do print response, dot text here.
Because it's an API response.
So ideally we can just read the text, let's see if that does anything.
So this return response will just have read.
Response like so.
If I run this.
Hey, look at that.
This is our response.
As you can see, it's a ton of hashed passwords.
There's a lot of them.
It looks like a couple of hundred.
So this is what we get from our response.
By using response to text, we get all the hashes that match the beginning of our hashed password.
Very cool.
What we can actually do.
You see over here how we get 24, three one.
And so on.
This shows you actually how many times these passwords have been hacked.
That's pretty cool.
So ideally we're able to grab the count, see if any of it matches with our tail, because now we can
just check the tail and also print out the count.
So instead of having a read response function, let's have a get.
Password.
Leaks.
Count function that receives the hashes or the response and the actual hash.
To check, which is our own password hash that we need to check against.
So we're going to check this hash to check and loop through all the hashes.
So we can do something again.
Nifty with Python here we can say hashes equals.
And we can use a tuple here and we can actually do a tuple comprehension which we've seen before.
I can say line dot split.
So we're going to split everything in the line, which is by these columns over here that you can see.
So that's the tail of the hash and the number of times it's been hacked.
So we're going to split it by the column.
And then we're going to loop and say four line.
So that's where the line comes from.
Four line in hashes.
Dot text.
Now, if I leave it like this, this actually won't work.
And I'll show you why in a second.
Actually, let's just do that now.
So let's see what print hashes will give us.
Instead of Reid response.
We'll run this one now.
So get password leaks account.
And if I run, let's clear this.
I get an error?
Well, I get an error because we have to add the hash to check as well.
So what should the hash to check be?
Well, it's the tail, right?
The tail of our actual password.
So I'm going to add the tail to the second parameter.
Save and run again.
All right, I get a response.
200 and I get a generator object.
This generator object, we can actually loop through rate.
So let's see what happens if I do four.
Remember, we have the hash and the count, so let's do hash h for hash and count in hashes because
remember we've converted to a tuple that has the hash and then the count.
Because we're splitting, remember?
So if we do this.
Let's just print each and count.
If I run this.
Hmm.
I get an error.
Value error.
Not enough values to unpack.
Expect it to gut one.
Hmm.
Why is that?
Let's just print H and see what happens.
And remove count for now.
Let's clear this and run this again.
Hmm.
It looks like we didn't split properly.
Every item is its own list.
So we actually have to use something called split lines here on our string.
And as you can see.
It returns a list of the lines in the string.
And it breaks at the line boundaries.
So when we actually do a four loop over the hash text, if we scroll up, let's see if we can see it.
No, it's not there anymore.
But if we scroll up, we just got a massive list of text.
Ideally on each line, we split this so that this line is well instead of each individual element,
the actual hash and count.
So we just need to do dot split lines like this.
If I save this and run once again.
That's a lot better.
So now we have what we want.
We can once again go back to what we have before, which is count.
And if we print H and count, let's save.
Run this again.
And that's a lot better.
We have each item separated.
Let's take a break and continue this in the next video.