Passed
Push — master ( 013bf5...b78558 )
by Justin
30:45 queued 26:47
created
plugins/ldaplogin/classes/ldapauthentificator.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -35,93 +35,93 @@
 block discarded – undo
35 35
 
36 36
 class LDAPAuthentificator implements IAuthentificator {
37 37
 
38
-	public function __construct() {
39
-		//
40
-	}
38
+    public function __construct() {
39
+        //
40
+    }
41 41
 
42
-	/**
43
-	 * check password of user and import user, if neccessary
44
-	 *
45
-	 * @param $username string name of user
46
-	 * @param $password string password of user
47
-	 *
48
-	 * @return userID or -1, if credentials are wrong
49
-	 */
50
-	public function checkPasswordAndImport(string $username, string $password): int {
51
-		//https://samjlevy.com/php-ldap-login/
42
+    /**
43
+     * check password of user and import user, if neccessary
44
+     *
45
+     * @param $username string name of user
46
+     * @param $password string password of user
47
+     *
48
+     * @return userID or -1, if credentials are wrong
49
+     */
50
+    public function checkPasswordAndImport(string $username, string $password): int {
51
+        //https://samjlevy.com/php-ldap-login/
52 52
 
53
-		//Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
53
+        //Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
54 54
 
55
-		//https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html
55
+        //https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html
56 56
 
57
-		//http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/
57
+        //http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/
58 58
 
59
-		//check, if username contains a komma (because komma is not allowed here)
60
-		if (strpos($username, ",") !== FALSE) {
61
-			throw new IllegalArgumentException("',' is not allowed in username.");
62
-			return -1;
63
-		}
59
+        //check, if username contains a komma (because komma is not allowed here)
60
+        if (strpos($username, ",") !== FALSE) {
61
+            throw new IllegalArgumentException("',' is not allowed in username.");
62
+            return -1;
63
+        }
64 64
 
65
-		$ldap_client = new LDAPClient();
65
+        $ldap_client = new LDAPClient();
66 66
 
67
-		//try to login user on ldap server
68
-		$res = $ldap_client->bind($username, $password);
67
+        //try to login user on ldap server
68
+        $res = $ldap_client->bind($username, $password);
69 69
 
70
-		if (!$res) {
71
-			//user doesnt exists or credentials are wrong
72
-			return -1;
73
-		}
70
+        if (!$res) {
71
+            //user doesnt exists or credentials are wrong
72
+            return -1;
73
+        }
74 74
 
75
-		//TODO: set user groups
75
+        //TODO: set user groups
76 76
 
77
-		//get attributes of user
78
-		$attributes = $ldap_client->listAllAttributesOfUser($username);
77
+        //get attributes of user
78
+        $attributes = $ldap_client->listAllAttributesOfUser($username);
79 79
 
80
-		$mail = "";
80
+        $mail = "";
81 81
 
82
-		//get mail of user
83
-		if (isset($attributes['mail'])) {
84
-			//get first mail
85
-			$mail = $attributes['mail'][0];
86
-		} else {
87
-			//generate random local mail
88
-			$mail = md5(PHPUtils::randomString(10) . time()) . "@local";
89
-		}
82
+        //get mail of user
83
+        if (isset($attributes['mail'])) {
84
+            //get first mail
85
+            $mail = $attributes['mail'][0];
86
+        } else {
87
+            //generate random local mail
88
+            $mail = md5(PHPUtils::randomString(10) . time()) . "@local";
89
+        }
90 90
 
91
-		$common_name = "";
91
+        $common_name = "";
92 92
 
93
-		if (isset($attributes['cn'])) {
94
-			$common_name = $attributes['cn'][0];
95
-		} else {
96
-			$common_name = $username;
97
-		}
93
+        if (isset($attributes['cn'])) {
94
+            $common_name = $attributes['cn'][0];
95
+        } else {
96
+            $common_name = $username;
97
+        }
98 98
 
99
-		//get surname
100
-		$surname = "";
99
+        //get surname
100
+        $surname = "";
101 101
 
102
-		if (isset($attributes['sn'])) {
103
-			$surname = $attributes['sn'][0];
104
-		}
102
+        if (isset($attributes['sn'])) {
103
+            $surname = $attributes['sn'][0];
104
+        }
105 105
 
106
-		//unbind
107
-		$ldap_client->unbind();
106
+        //unbind
107
+        $ldap_client->unbind();
108 108
 
109
-		//check, if we have to import user
110
-		if (!User::existsUsername($username)) {
111
-			//generate random password
112
-			$password = md5(PHPUtils::randomString(16) . time());
109
+        //check, if we have to import user
110
+        if (!User::existsUsername($username)) {
111
+            //generate random password
112
+            $password = md5(PHPUtils::randomString(16) . time());
113 113
 
114
-			//import user and create user in database
115
-			$userID = User::create($username, $password, $mail, PHPUtils::getClientIP(), 2, "none", 1, "Plugin\\LDAPLogin\\LDAPAuthentificator");
114
+            //import user and create user in database
115
+            $userID = User::create($username, $password, $mail, PHPUtils::getClientIP(), 2, "none", 1, "Plugin\\LDAPLogin\\LDAPAuthentificator");
116 116
 
117
-			echo "userID: " . $userID;
117
+            echo "userID: " . $userID;
118 118
 
119
-			return $userID['userID'];
120
-		} else {
121
-			//return userID
122
-			return User::getIDByUsernameFromDB($username);
123
-		}
124
-	}
119
+            return $userID['userID'];
120
+        } else {
121
+            //return userID
122
+            return User::getIDByUsernameFromDB($username);
123
+        }
124
+    }
125 125
 }
126 126
 
127 127
 ?>
Please login to merge, or discard this patch.