note 38243 added to function.ldap-compare
| From: | andre dot varney at apollis dot com | Date: | Sat, 13 Dec 2003 14:17:57 +0000 |
| Subject: | note 38243 added to function.ldap-compare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61902@lists.php.net to get a copy of this message | ||
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é
----
Manual Page -- http://www.php.net/manual/en/function.ldap-compare.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38243
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38243&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38243&report=yes
Search -- http://master.php.net/manage/user-notes.php