@@ -56,16 +56,10 @@ public function retrieveByCredentials(array $credentials)
5656 // If the user is an Adldap User model instance.
5757 if ($ user instanceof User) {
5858 // Retrieve the users login attribute.
59- $ username = $ user ->{$ this ->getLoginAttribute ()};
60-
61- if (is_array ($ username )) {
62- // We'll make sure we retrieve the users first username
63- // attribute if it's contained in an array.
64- $ username = Arr::get ($ username , 0 );
65- }
59+ $ username = $ this ->getUsernameFromUser ($ user );
6660
6761 // Retrieve the password from the submitted credentials.
68- $ password = Arr:: get ( $ credentials , $ this ->getPasswordKey () );
62+ $ password = $ this ->getPasswordFromCredentials ( $ credentials );
6963
7064 // Try to log the user in.
7165 if (!is_null ($ password ) && $ this ->authenticate ($ username , $ password )) {
@@ -84,8 +78,21 @@ public function retrieveByCredentials(array $credentials)
8478 }
8579
8680 /**
87- * Retrieves the Adldap User model from the
88- * specified Laravel model.
81+ * {@inheritdoc}
82+ */
83+ public function validateCredentials (Authenticatable $ user , array $ credentials )
84+ {
85+ if ($ this ->getPasswordSync ()) {
86+ // If password syncing is enabled. We can hit our
87+ // local database to check the hashed password.
88+ return parent ::validateCredentials ($ user , $ credentials );
89+ }
90+
91+ return true ;
92+ }
93+
94+ /**
95+ * Retrieves the Adldap User model from the specified Laravel model.
8996 *
9097 * @param mixed $model
9198 *
@@ -123,6 +130,38 @@ protected function authenticate($username, $password)
123130 return $ this ->getAdldap ()->auth ()->attempt ($ username , $ password );
124131 }
125132
133+ /**
134+ * Returns the configured username from the specified AD user.
135+ *
136+ * @param User $user
137+ *
138+ * @return string
139+ */
140+ protected function getUsernameFromUser (User $ user )
141+ {
142+ $ username = $ user ->{$ this ->getLoginAttribute ()};
143+
144+ if (is_array ($ username )) {
145+ // We'll make sure we retrieve the users first username
146+ // attribute if it's contained in an array.
147+ $ username = Arr::get ($ username , 0 );
148+ }
149+
150+ return $ username ;
151+ }
152+
153+ /**
154+ * Returns the configured users password from the credentials array.
155+ *
156+ * @param array $credentials
157+ *
158+ * @return string
159+ */
160+ protected function getPasswordFromCredentials (array $ credentials = [])
161+ {
162+ return Arr::get ($ credentials , $ this ->getPasswordKey ());
163+ }
164+
126165 /**
127166 * Returns the password key to retrieve the
128167 * password from the user input array.
0 commit comments