note 98478 deleted from function.md5 by degeberg

From: Date: Thu, 17 Jun 2010 20:44:03 +0000
Subject: note 98478 deleted from function.md5 by degeberg
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170221@lists.php.net to get a copy of this message
Note Submitter: danny at devtrixlabs dot com ---- 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; } ?>

« previous php.notes (#170221) next »