You should all just keep the passwords as plaintext and use it to
measure customer intelligence.
/s


On Mon, Feb 1, 2010 at 11:29 AM, Stig Manning <[email protected]> wrote:
> yeosteve wrote:
>>
>> SHA1 is just as easy to crack now, apparently.  Salted SHA256 is the
>> way to go, perhaps something like
>>
>> $pwd = $_POST['pwd'];
>> $salt = sha1(md5($pwd);
>>
>> $encrypted = hash('sha256', $pwd.$salt);
>>
>> Noone's going to be able to use a reverse lookup to get the original
>> password, if they do get into your database, and if anyone can see
>> your code to see how you mixed things up, you've lost anyway, but I'd
>> be interested to see how others do this.
>>
>> Steve
>>
>
> Hi Steve,
>
> That is not exactly true, switching your hash to one with less chance of
> collisions is not actually improving security. The main problem is the
> possibility of your code and database being compromised, with the above code
> you can get a common-password dictionary and generate hashes using your code
> for each dictionary word, giving the ability to find insecure passwords in
> the database. As the above hash generation logic is indentical for each
> interation (each password that is generated) you are as 'safe' as if you
> were using a fixed salt. If your database is compromised, a hacker would be
> able to create a dictionary of hashes using a common-passwords dictionary
> and look for insecure passwords. If your database contains a large number of
> users then you are guaranteed to have compromised accounts.
>
> A better method is to generate a unique one-time salt for each interaction
> (each password) and storing this along with the password.  Each password
> hash is created with a unique salt, so if the password is re-hashed or if a
> dictionary word is re-hashed, you cannot match them up.
>
> Here is some simple code for achieving very good security:
>
> $salt = substr(sha1(uniqid(mt_rand(), true)), -10);  //Generate a 10
> character salt
> $password_hash = $salt . sha1($salt . $password); //Concatenate salt and
> plain text password
>
> Stored password is now 50 characters, 10 character salt and 40 character
> hash.
> Then to compare:
>
> $salt = substr($password_hash, 0, 10); //Extract salt
> if(sha1($salt . $compare_password) == substr($password_hash, 10))
> {
>  return true;
> }
>
> This has the benefit of having a unique salt for each record, and having the
> salt storage in the same field. It is also security through obfuscation due
> to the uncommon length of the password hash (50 characters) and the
> inability to immediately see where the salt is stored.
>
> Hope this helps!
>
> Cheers,
> Stig Manning
>
>
> --
> NZ PHP Users Group: http://groups.google.com/group/nzphpug
> To post, send email to [email protected]
> To unsubscribe, send email to
> [email protected]

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to