From: Stricted Date: Fri, 21 Feb 2014 08:49:16 +0000 (+0100) Subject: fix syntax X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=702bd31cd8492a9c86761f0fe4ff037b90a89452;p=Snippets.git fix syntax --- diff --git a/LDAP.class.php b/LDAP.class.php index 491e260..8063760 100644 --- a/LDAP.class.php +++ b/LDAP.class.php @@ -10,7 +10,7 @@ class LDAP { * LDAP resource id * @var object */ - protected $ldap = Null; + protected $ldap = null; /** * LDAP DN @@ -75,7 +75,7 @@ class LDAP { or see here: http://techiesf1.blogspot.de/2012/03/add-ldap-user-from-php.html */ if (is_array($user) && !empty($user)) { - if (ldap_add($this->ldap, "uid=".$user['uid'].",".$this->dn, $user) { + if (ldap_add($this->ldap, "uid=".$user['uid'].",".$this->dn, $user)) { return true; } } diff --git a/LDAPHash.class.php b/LDAPHash.class.php index c3ef96d..1afb97d 100644 --- a/LDAPHash.class.php +++ b/LDAPHash.class.php @@ -14,75 +14,75 @@ class LDAPHash { */ public function compare($password, $hash) { // replace hash method to lowercase - $search = array("SSHA", "SHA256", "SHA384", "SHA512", "SSHA256", "SSHA384", "SSHA512", "MD5", "SMD5", "SHA", "CRYPT"); - $replace = array("ssha", "sha256", "sha384", "sha512", "ssha256", "ssha384", "ssha512", "md5", "smd5", "sha", "crypt"); - $hash = str_replace($search, $replace, $hash); - + $search = array("SSHA", "SHA256", "SHA384", "SHA512", "SSHA256", "SSHA384", "SSHA512", "MD5", "SMD5", "SHA", "CRYPT"); + $replace = array("ssha", "sha256", "sha384", "sha512", "ssha256", "ssha384", "ssha512", "md5", "smd5", "sha", "crypt"); + $hash = str_replace($search, $replace, $hash); + $encrypted_password = ''; - + // plain password if ($password == $hash) { return true; } - + preg_match("/^{([a-z0-9]+)}([\s\S]+)/i", $hash, $method); if (isset($method[1]) && !empty($method[1]) && isset($method[2]) && !empty($method[2])) { switch ($method[1]) { case "md5": $encrypted_password = '{md5}' . base64_encode(hash("md5", $password, true)); break; - + case "smd5": - $salt = substr(base64_decode($method[2]),16); + $salt = substr(base64_decode($method[2]), 16); $encrypted_password = '{smd5}' . base64_encode(hash("md5", $password.$salt, true).$salt); break; - + case "sha": $encrypted_password = '{sha}' . base64_encode(hash("sha1", $password, true)); break; - + case "ssha": - $salt = substr(base64_decode($method[2]),20); + $salt = substr(base64_decode($method[2]), 20); $encrypted_password = '{ssha}' . base64_encode(hash("sha1", $password.$salt, true).$salt); break; - + case "sha256": $encrypted_password = "{sha256}".base64_encode(hash("sha256", $password, true)); break; - + case "ssha256": - $salt = substr(base64_decode($method[2]),32); + $salt = substr(base64_decode($method[2]), 32); $encrypted_password = "{ssha256}".base64_encode(hash("sha256", $password.$salt, true).$salt); break; - + case "sha384": $encrypted_password = "{sha384}".base64_encode(hash("sha348", $password, true)); break; - + case "ssha384": - $salt = substr(base64_decode($method[2]),48); + $salt = substr(base64_decode($method[2]), 48); $encrypted_password = "{ssha384}".base64_encode(hash("sha384", $password.$salt, true).$salt); break; - + case "sha512": $encrypted_password = "{sha512}".base64_encode(hash("sha512", $password, true)); break; - + case "ssha512": - $salt = substr(base64_decode($method[2]),64); + $salt = substr(base64_decode($method[2]), 64); $encrypted_password = "{sha512}".base64_encode(hash("sha512", $password.$salt, true).$salt); break; - + case "crypt": $encrypted_password = "{crypt}".crypt($password, $method[2]); break; - + default: die("Unsupported password hash format"); break; } } - + if ($hash == $encrypted_password) { return true; } @@ -90,7 +90,7 @@ class LDAPHash { return false; } } - + /** * return supported hash methods * @@ -99,7 +99,7 @@ class LDAPHash { public function supportedMethods () { return array("ssha", "sha256", "sha384", "sha512", "ssha256", "ssha384", "ssha512", "md5", "smd5", "sha", "crypt", "plain"); } - + /** * hash given password with given hash method * @@ -114,56 +114,56 @@ class LDAPHash { case "ssha": $hash = base64_encode(hash("sha1", $password.$salt, true).$salt); break; - + case "sha256": $hash = base64_encode(hash("sha256", $password, true)); break; - + case "sha384": $hash = base64_encode(hash("sha384", $password, true)); break; - + case "sha512": $hash = base64_encode(hash("sha512", $password, true)); break; - + case "ssha256": $hash = base64_encode(hash("sha256", $password.$salt, true).$salt); break; - + case "ssha384": $hash = base64_encode(hash("sha384", $password.$salt, true).$salt); break; - + case "ssha512": $hash = base64_encode(hash("sha512", $password.$salt, true).$salt); break; - + case "md5": $hash = base64_encode(hash("md5", $password, true)); break; - + case "smd5": $hash = base64_encode(hash("md5", $password.$salt, true).$salt); break; - + case "sha": $hash = base64_encode(hash("sha1", $password, true)); break; - + case "crypt": $hash = crypt($password, $salt); break; - + case "plain": $hash = $password; break; - + default : die("Unsupported hash method"); break; } - + return ($method == "plain" ? "" : "{".$method."}").$hash; } }