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
https://forums.phpfreaks.com/topic/266250-password-hashing-method-good-enough/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.