Am working on a project & am keen to keep password-storage secure from the start. In the idea phase, but this is roughly what I intend to use.
class Crypto {
public function hash1($string, $salt) {
return hash('sha512', $string . $salt);
}
public function hash2($string, $salt) {
return hash('sha512', $salt . $string);
}
public function compareToHash($string, $salt, $hash1, $hash2) {
return($this->hash1($string, $salt) === $hash1 && $this->hash2($string, $salt) === $hash2);
}
}
As you can see I am trying to avoid collisions. Is this an effective way, it seems awfully simple and I wonder if I am missing something.
Thanks.
Since you plan on password protecting possibly a website, let me explain that you will need to make sure to send a password from the client already encoded or else any sniffer will find the real password, and you know how people usually use password, right? The same on many, many accounts.
I would suggest taking a look at a post I stubled upon some time ago, and preserved a link for it, for it explains all the problems with hashing and password protection: http://www.codinghorror.com/blog/2007/09/rainbow-hash-cracking.html
Shortly - use the strongest (and sha1 is not strong any more) password encoder as it is possible. Not the fastest one. Let the hacker loose valuable time trying to break in. So much, that breaking in will become unattractive.
Hope it will help, and good luck.