note 98478 added to function.md5
| From: | danny at devtrixlabs dot com | Date: | Thu, 17 Jun 2010 20:38:46 +0000 |
| Subject: | note 98478 added to function.md5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170220@lists.php.net to get a copy of this message | ||
These functions create a MD5 encrypted password with a randomly selected salt. The salt id is then
tagged onto the hash for decryption.
You can put your own salt hashes in the findSalt() function. You can increase the amounts of salts
in this function as well and modify the rand() to your liking.
<?php
function generateEncryptedPassword($plain)
{
$s = rand(1,5);
$salt = findSalt($s);
$encrypted = md5($salt . $plain).':'.$s;
return $encrypted;
}
function authEncryptedPassword($plain,$encrypted)
{
$temp = explode(':',$encrypted);
if(sizeof($temp)==2) {
$salt = findSalt($temp[1]);
if(md5($salt.$plain)==$temp[0]) {
return true;
} else {
return false;
}
} else {
return false;
}
}
function findSalt($s) {
switch($s) {
case '1':
$salt = '3b0c06d1aa30703fc3bbb3375ec7aee0'; // random hash
break;
case '2':
$salt = '4a6898d364488a8a70bc3a0de6fe9727'; // random hash
break;
case '4':
$salt = 'a9cdebe2bfdca7a0da9a119a4c923a5d'; // random hash
break;
case '5':
$salt = '5f2fe5e261d983a403de38813693e78e'; // random hash
break;
}
return $salt;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 74.7.52.30
----
Manual Page -- http://www.php.net/manual/en/function.md5.php
Edit -- https://master.php.net/note/edit/98478
Del: integrated -- https://master.php.net/note/delete/98478/integrated
Del: useless -- https://master.php.net/note/delete/98478/useless
Del: bad code -- https://master.php.net/note/delete/98478/bad+code
Del: spam -- https://master.php.net/note/delete/98478/spam
Del: non-english -- https://master.php.net/note/delete/98478/non-english
Del: in docs -- https://master.php.net/note/delete/98478/in+docs
Del: other reasons-- https://master.php.net/note/delete/98478
Reject -- https://master.php.net/note/reject/98478
Search -- https://master.php.net/manage/user-notes.php