Jump to content

[SOLVED] Check a hash value in a query


limitphp

Recommended Posts

I'm running a query:

mysql_query("UPDATE user SET verified = 1 WHERE hash('md5',username.$salt) = '$usernameHash'") or die (mysql_error());

 

I'm trying to see if the usernameHash equals the username in the user table.

 

Will this query work?

Can you put a hash in a mysql_query?  The column name in the user table is username.

Link to comment
Share on other sites

mysql_query("UPDATE user SET verified = 1 WHERE hash('md5',username.$salt) = '$usernameHash'") or die (mysql_error());

if anything would look like this

mysql_query("UPDATE user SET verified = 1 WHERE 14c4b06b824ec593239362517f538b29 = '$usernameHash'") or die (mysql_error());

possibly:

$usernameHash = md5($username.$salt);
mysql_query("UPDATE user SET verified = 1 WHERE username = '$usernameHash'") or die (mysql_error());

 

???

Link to comment
Share on other sites

you store the username in plain text in the db, right?

why not query it in plain text?

it may take a second longer to process, but you query the users table, get all of the usernames, and run a loop where you hash the username from the db and match it to the username you are trying to find. if !=, move on to the next one. When you get the one ==, use that one to make your sessions or whatever.

Link to comment
Share on other sites

Yes.  I store the username in plain text in the db.

 

I send them a link after they register with their hashed username and a uniquID.

 

I then check it against their hashed username and uniquID I have in a table.

If it matches, I update their info in the user table...I set the verify column to 1.

 

But yuo see, all I have is their usernameHash.

 

So i need to check their usernameHash against their username in the table somehow.

 

You can't

UPDATE user SET verified = 1 WHERE hash('md5',username.$salt) = '$usernameHash'") or die (mysql_error());

 

I thought you could......maybe UPDATE user SET verified = 1 WHERE md5(username.$salt) = '$usernameHash'") or die (mysql_error());

Link to comment
Share on other sites

Personally (this isn't necessarily helping you) I would use a GUID not a hashed username or such.

 

So you'd need one more field in your table, something like verify_guid

 

The email link would look something like verify?id=6B6BDDA6-C86B-11DD-8489-AE5355D89593

 

Then check that against your database

Link to comment
Share on other sites

can I ask simply why you want to hash the username?

 

simply for extra security.

 

I create a md5(uniquID.$salt) and a md5(username.$salt).

Both are sent to user's email as querystrings.

 

I figure it'll be more difficult to guess both. 

 

When they click on the link, it takes them to a page...and the page checks BOTH querystrings against the values of both in a table.

 

Once they match, I update the user's info and set verified to 1.

Link to comment
Share on other sites

I guess what I'll do is after they successfully register , I'll send 3 things to the temp table that has their verificationID....

a verificationID, hashed username and a regular username.

Then I can just grab the unhashed username from the table and use that to match the user's info and update their profile.

Link to comment
Share on other sites

I usually make it so that when they register, if makes a random string then hashes it. sends them an email with that string in their URL query string. I use the string as one field in a table with other fields like username, password, email, ect...

when they go to the page (something like confirm.php?regisr=14c4b06b824ec593239362517f538b29)

it queries the table in whatever field you set  to the random string. If the query returns a row, use the row to make a user and give them a pretty "Welcome" message. The likeliness of someone guessing a randomly created md5 is less then their chance of getting struck by lightening if they walked around in every lightening storm for a year carrying a 10foot metal pole. lol

This is pretty damn secure i'd say cuz this is how major sites like myspace do it.

Link to comment
Share on other sites

When I said it's all in the name, I was talking with regards to using it as a unique identifier to identify a registered user in the verification process

 

As far as what they do goes, there is no difference, the only difference is in the name

 

Globally Unique Identifier

Universally Unique Identifier

 

They both produce a 128 bit number, normally presented in the following hexadecimal - grouped form

 

6B6BDDA6-C86B-11DD-8489-AE5355D89593

 

Link to comment
Share on other sites

That would work, but a GUID is a 'standard' way of doing this GUID = 'Globally Unique Identifier' it's all in the name ;)

 

Everything is already written, is there a bg difference in GUID compared to md5(unqiuID.$salt)?

 

is 128 bit going to be 32 chacaters long?  just curious....

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.