Welcome Guest, Not a member yet? Register   Sign In
Comparing a md5 encrypted username to the datase
#1

[eluser]Bianca Migueis[/eluser]
Hi,
when people log in at my website the code encrypts their username with MD5 and stores it into a cookie and at the same time it updates the database with remember_me=true where 'user'=$user. My question is... later on how do i compare the MD5 encrypted user with the database? I basically want to find the place in the database where the user is equal to my MD5 encryption AND remember_me=true. I can't figure out how to do it except by returning the entire user database, encrypting all the usernames with MD5 and THEN comparing. Is there an easier way to do that?

EDIT: Should I create another field in the database to store the MD5 version of the usernames?
#2

[eluser]sunset11[/eluser]
Hi Bianca

Not sure this is what you need.

You just have to encrypt the username you receive with the native php function md5($string) and then compare this value with your field.

$username_md5 = md5($username)
and then
"SELECT * FROM TABLE WHERE username_field_name = '$username_md5' AND remember_me = 1"
#3

[eluser]Bianca Migueis[/eluser]
but then I would have to return every single username in the database. This is a website that can get really big so I would rather not return every single username entry and encrypt each of them before being able to test them. Thank you for your input though Smile

I ended up creating a username_MD5 field in my database but I would still like to hear other people if they have a better solution.
#4

[eluser]isawhat[/eluser]
Using AES or another encryption would be a better option then MD5 to store the username in the cookie, then you can just decrypt it and search for the normal username rather then add another field to the table.




Theme © iAndrew 2016 - Forum software by © MyBB