What is wrong with my login?
AzureScripts (164)

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?


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

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:


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 (164)

@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 (209)

@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 (164)

@JustARatherRidi Sort of banned from discord .-.

JustARatherRidi (209)

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

TristanMisja (34)

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

JustARatherRidi (209)

@TristanMisja Haha thanks, I try where I can 😄