What is wrong with my login?
AzureScripts (151)

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
Username: oof
Password: oof

However, this one doesn't
Username: leon
Password: owner

What am i doing wrong?

https://repl.it/@AzureScripts/Secure-Login

You are viewing a single comment. View All
JustARatherRidi (191)

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 database:

be008694d286a420f6997bef8ff566f892182d0cedf60b4a4d9cc40028d0501abe008694d286a420f6997bef8ff566f892182d0cedf60b4a4d9cc40028d0501a
\nb17029586f80d6c56525344c2729dfada943be02dc1e8eacbe8ddc15e80e681c380c2e9d6ee0722dd6942cdb9b2f4cf9b8fdd7934347429fced81b99f8655bb
d

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 os.system('clear').


Hope this helped, let me know if you get stuck anywhere!

AzureScripts (151)

@JustARatherRidi Perfect, thank you! So i didn't need that "for line in database" thing after all!

Hey, if you ever wanna work on this with me, just let me know!

JustARatherRidi (191)

@AzureScripts No problem at all!

I'm a little busy with school as of now, so I can't commit to being able to work on things :/

If you want any help in what you're doing though, hit me up on Discord @ARatherLongUsername#3145 and I'll look into it when I can!

AzureScripts (151)

@JustARatherRidi Sort of banned from discord .-.

JustARatherRidi (191)

@AzureScripts oh okay, let me know what works for you then.

TristanMisja (24)

@JustARatherRidi Wow you know a lot! You also answered my question!

JustARatherRidi (191)

@TristanMisja Haha thanks, I try where I can 😄