I am trying to make a very secure login, not advanced, but basic.
And it works perfectly fine!
However, it only works fine for one of the users.
Here are some credentials that you can use to test
This one works perfectly fine
However, this one doesn't
What am i doing wrong?
I see you've made more progress, nice job!
The problem is that you are iterating over your
database object. When you say
for line in database, you get 128 characters each iteration, not one line at a time (You can see this for yourself in this line of the source code). Here's why that's a problem.
Each of your hashes are 128 characters long. So in the first iteration, you get your entire first has as a string. This is why logging in with
oof/oof works. Now, after your first hash, you've got a line break (
\n) before your next hash. Line breaks are counted as a character, so in iteration #2, what you get is the line break followed by the first 127 characters of your second hash. The
\n and 127 characters add up to 128 characters, which is why it stops there. Finally, in iteration #3, you get that last character of your second hash.
Just to be clear, these are the 3 strings you get when you iterate over
So as you can tell, the second hash doesnt match up with the encryption because there's a character missing in the end and there's an extra line break in the beginning.
Fixing this is actually quite easy. Instead of iterating over each 128 characters, all you need to do is just check whether the hash is in your database's content.
if the_hash in database.content: # Logged in successfully
Here's a working repl
Tip: Instead of printing a lot of empty lines, you can clear the screen using
Hope this helped, let me know if you get stuck anywhere!