views:

79

answers:

5

I was wondering to hash the password in PHP using different methods available and the combination of them for more and more security. I was wondering if this would work..?

$pass = "***";
$salt = "!@)#%%@(#&@_!R151";
$pass = sha1($pass.$salt);
$pass = md5($pass);
+5  A: 

Nope. Combinations do not add any security.
Actually you made it less secure. Theoretically, but anyway.

I have a feeling that hashing issues are way overestimated.
Nobody concerns in any other security issue but everyone anxious to make a hash unbreakable in a billion years. Relax, buddy. There are thousands other ways to break your app.

Col. Shrapnel
You can add security to your password using other ways like splitting the hashed password and storing it somewhere else. (saw this technique in gallery2)
sheeks06
@sheeks the only question - do you really need it?
Col. Shrapnel
No. :) just sharing. might be useful to him.
sheeks06
A: 

I guess adding a salt is enough, but if you want more maybe do:

sha1($salt. sha1($salt. $pass));

and let $salt contain some non-printed chars, arbitrary binary data or anything like that.

Again, I guess this won't add much since implementation I saw only add $salt, but why not more security for the coming ages : )

aularon
+4  A: 

Rather than that, you can use a stronger hashing algorithm like sha512 with combination of a strong salt and UserID: Do it like this:

 echo hash('sha512', 'MyPassword' . $StrongSalt . $UserID);

SHA512 is actually SHA-2 for which there are no collisions found. See at wikipedia.

shamittomar
Ummm, won't that defeat the point? Since `microtime()` is not reproducible, you just created a hash that you can't verify (unless you store it somewhere)...
ircmaxell
@ircmaxell, Ohh yes, I just forgot that part. Thanks for reminding. Fixed it :)
shamittomar
+1 then... (Since using a stronger algorithm is good advice in general)...
ircmaxell
Klinky
@Kilnky, by appending `$UserID`, it makes the sale unique for every user.
shamittomar
True, but what is the point of $StrongSalt ? A unique salt(e.g. userId) is about as strong as you're going to get.
Klinky
I think whirlpool is pretty elite, as far as hashes go. It's my favorite for some reason, and is supported by the PHP `hash` function.
Alex JL
A: 

Your passwords will most likely, never be 100% secure.

Try looking at a nonce. Which should be generated for each individual user.

Russell Dias
you mean each salt should be a nonce?
tunetosuraj
A: 

IF you are going to do this, don't just MD5 the result:

$pass = "***";
$salt = "!@)#%%@(#&@_!R151";
$pass = sha1($pass.$salt);
$pass = md5($pass);

Instead, run md5 on the result and the inputs...

$pass = "***";
$salt = "!@)#%%@(#&@_!R151";
$tmp = sha1($pass.$salt);
$pass = md5($tmp . $pass . $salt);

The reason is that if you do md5(sha1()), you're basically increasing the chances of collision. The reason is that all sha1 collisions would automatically be collisions in the md5 call (hence it's a superset of the collisions). By re-entering the password and salt, you're preventing that from happening, and hence creating a "stronger" hash rather than a weaker one...

ircmaxell
If I understand these things correctly, when I brute force this pass, first MD5 collision will let me in, no matter it's arguments. Where I am wrong?
Col. Shrapnel
@Col: Yes, the first `md5` collision will let you in. That's always the case. But if you just do `md5(sha1(stuff))`, you can find either a `md5` collision **OR** a `sha1` collision. Either will let you in fine. Whereas if you do `md5(sha1(stuff) . stuff)`, you're eliminating that issue. As for why to hash multiple times, you can read [more about it in this question/answer](http://stackoverflow.com/questions/3559437/many-hash-iterations-append-salt-every-time/3559497#3559497)... Oh, and I'm not trying to suggest to use this method (`md5(sha1())`), only **IF** it's used...
ircmaxell
This odd behavior again. Why to answer at all if you do not suggest your answer yourself? I can't stand it.
Col. Shrapnel
@Col: I'm saying that IF he's going to do it in the first place, he may as well do it right. I wouldn't do it personally (I'd much rather do a number of rounds of `sha512`), but that doesn't mean it's "bad" to do. The answer that I gave pointed out a fundamental flaw (albeit a small one) in the solution he provided...
ircmaxell