note 38243 deleted from function.ldap-compare by victor

From: Date: Sun, 14 Dec 2003 19:12:20 +0000
Subject: note 38243 deleted from function.ldap-compare by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-61943@lists.php.net to get a copy of this message
Note Submitter: andre.varney@apollis.com ---- Here is some function that I wrote to verify both plain text and SSHA encrypted passwords as used with the "userPassword" attribute. It shouldn't be to hard to add more algorithms. function password_check($pwd='', $digest='') { // parse digest ({algorithm}hash) if (!preg_match_all("/^(\{(\w+)\})?(.*)$/", $digest, $matchAr)) { echo 'Unexpected digest format'; return false; } $algorithm = strtoupper($matchAr[2][0]); $hash = $matchAr[3][0]; // algorithm specific handler switch ($algorithm) { case '': // plain text password comparison return ($pwd == $hash); case 'SSH': case 'SSHA': // SSHA password comparison $bin = base64_decode($hash); $salt = substr($bin, -4); $ssh_hash = substr($bin, 0, 20); return ($ssh_hash == mhash(MHASH_SHA1, $pwd.$salt)); } echo "Unsupported Algorithm [$algorithm]"; return false; } Cheers, André

« previous php.notes (#61943) next »