Jump to content

[SOLVED] Double hashing password with salt


hostfreak

Recommended Posts

Hey, I have the following code:

<?php
//Password
$Password = 'Password';

//Generate random number
$Random_Num = rand(48, 122);
//Convert random number to a real character
$Salt = chr($Random_Num);

//Double hash password /w Salt
$Secure_Password = md5(sha1($Password.$Salt));
?>

 

I was just wondering how efficient it is to double hash? And if using both md5 and sha1 in conjunction like that is alright? I've seen double hashing with the same function like md5(md5()), not like the above though. Also, in general, is the above pretty sound, security wise?

Link to comment
Share on other sites

Double salting is overkill. However, MD5ing a password and then using native database functions to encrypt stuff might be acceptable.

 

That being said to validate the password you'll have to store the random number in the database as well. What I've done in the past is use userid as a salt and concatenate it on either the beginning or end of the password (or both) and then hash it.

Link to comment
Share on other sites

Ok lets talk through this.

 

Using your code:

<?php
//Password
$Password = 'Password';

//Generate random number
$Random_Num = rand(48, 122);
//Convert random number to a real character
$Salt = chr($Random_Num);

//Double hash password /w Salt
$Secure_Password = md5(sha1($Password.$Salt));

print $Secure_Password
?>

 

Refresh this page 5 times, you'll get 5 different results, right? That's bad. Your users will never be able to login :)

 

Link to comment
Share on other sites

Also, the character length returned by default for both functions (md5, sha1) is different. So if I double hash using each function, both return a different length of characters. Therefore, isn't that defeating the purpose of each (when using them in conjunction with each other)? The returned character length would follow the main functions, in this case md5, correct?

Link to comment
Share on other sites

So stick to one hashing function & if possible use database functions for extra encryption. Then the salt, instead of a random number should/could be a userid or something pertaining to whomever the password is assigned to and is also stored in the database? Makes sense. Then security wise, that should be pretty sound?

Link to comment
Share on other sites

Alright, so if I get rid of the double hashing and store the random salt in a database (therefore making it static, for each password), maybe some database encryption, the hash would be pretty sound then, correct?

 

Right now, I am just focusing on the hash alone.

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.