Jump to content

Password hashing method good enough?


MySQL_Narb

Recommended Posts

Is this good password hashing/encryption? Will this protect weaker passwords?

 

        $salt = substr(hash(sha256, sha1(time())), 10);
        $password = $salt.hash(sha256, md5(sha1($_POST['password']))).substr($salt, 0, -51);
        
        $_SESSION['salt'] = $salt;
        $_SESSION['password'] = $password;

Link to comment
Share on other sites

1. 'sha256' is not a constant. You need to quote it in your function call. You could code with all errors displayed. See my sig.

 

2. There's no point in double hashing. hash('sha256', sha1(time())) and hash('sha256', md5(sha1($_POST['password']))) Just use one call per hash

 

3. You don't actually mix the salt in with the hash. You have to do something like

$pass = $salt.'|'.hash('sha256',$_POST['password'].$salt);

I added the bar in between to easily split the salt and hash later for checking.

 

4. To mix the salt and the password, ideally, you use hash_hmac instead. It mixes it in a 'standard' way, and it's very easy to use.

$pass = $salt.'|'.hash_hmac('sha256',$_POST['password'],$salt);

 

5. For the salt, you want to be sure it's unique. Use microtime and something like a session ID, or IP, user-agent, etc.

 

6. If you're interested in securing your user-based application, you really should read the article in my signature. The examples aren't production code, but the concept is there and it goes way beyond just hashing.

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.