fix syntax
authorStricted <info@nexus-irc.de>
Fri, 21 Feb 2014 08:49:16 +0000 (09:49 +0100)
committerStricted <info@nexus-irc.de>
Fri, 21 Feb 2014 08:49:16 +0000 (09:49 +0100)
LDAP.class.php
LDAPHash.class.php

index 491e260d61e9b2b0f7b142dfe1547c425a6b4164..8063760aedcb874e7b9d1ff456050342ac9fb2f0 100644 (file)
@@ -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;
                        }
                }
index c3ef96dd0deb7d615d59d98fe2e88459a1969133..1afb97dabae3c0af6b6be7ed809888616f9eaa0d 100644 (file)
@@ -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;
        }
 }