note 98418 deleted from function.md5 by danbrown

From: Date: Mon, 14 Jun 2010 21:51:33 +0000
Subject: note 98418 deleted from function.md5 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170126@lists.php.net to get a copy of this message
Note Submitter: danny at devtrixlabs dot com ---- Here is an example of a MD5 password generator and authenticator. It uses a random salt (chosen from 4, and appends the salt id to the end of the hash). <?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 (#170126) next »