note 85005 deleted from function.md5 by joey
| From: | joey@php.net | Date: | Sun, 17 Jul 2011 08:39:30 +0000 |
| Subject: | note 85005 deleted from function.md5 by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181604@lists.php.net to get a copy of this message | ||
Note Submitter: pegler [at] googleemaildomain [dot] com
----
I have been playing around with coming up with some sort of more secure md5 encryption. This
combines several techniques described so far. First it will encrypt the password using md5. Then
rotate the text using the length of the original password, then encrypt the password again using md5
while adding a salt.
My reasoning for only rotating the hash around hex characters is to make the rotated hash a possible
hash itself. If we rotated around all characters, it would be possible to guess the original hash
by looking at non-hex characters in the rotated hash. Combining this hash with a fairly large salt
should minimize collisions when hashing again.
See the other comments as to why double encrypting a password is usually a bad idea.
For the salt I am using a 128 character randomly generated string.
<?php
function hashPassword($password)
{
$salt = "some_long_random_string";
//encrypt the password, rotate characters by length of original password
$len = strlen($password);
$password = md5($password);
$password = rotateHEX($password,$len);
return md5($salt.$password);
}
function rotateHEX($string, $n)
{
//for more security, randomize this string
$chars="abcdef1234567890";
$str="";
for ($i=0;$i<strlen($string);$i++)
{
$pos = strpos($chars,$string[$i]);
$pos += $n;
if ($pos>=strlen($chars))
$pos = $pos % strlen($chars);
$str.=$chars[$pos];
}
return $str;
}
?>