Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 520587d

Browse files
committed
Added set model password check for mutator
1 parent 308ac0a commit 520587d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/AdldapAuthUserProvider.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Adldap\Models\User;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Facades\Config;
10+
use Illuminate\Database\Eloquent\Model;
1011
use Illuminate\Contracts\Auth\Authenticatable;
1112
use Illuminate\Auth\EloquentUserProvider;
1213

@@ -85,36 +86,36 @@ public function retrieveByCredentials(array $credentials)
8586
*/
8687
protected function getModelFromAdldap(User $user, $password)
8788
{
88-
// Get the username attributes
89+
// Get the username attributes.
8990
$attributes = $this->getUsernameAttribute();
9091

91-
// Get the model key
92+
// Get the model key.
9293
$key = key($attributes);
9394

94-
// Get the username from the AD model
95+
// Get the username from the AD model.
9596
$username = $user->{$attributes[$key]};
9697

9798
// Make sure we retrieve the first username
98-
// result if it's an array
99+
// result if it's an array.
99100
if (is_array($username)) {
100101
$username = Arr::get($username, 0);
101102
}
102103

103-
// Try to retrieve the model from the model key and AD username
104+
// Try to retrieve the model from the model key and AD username.
104105
$model = $this->createModel()->newQuery()->where([$key => $username])->first();
105106

106-
// Create the model instance of it isn't found
107+
// Create the model instance of it isn't found.
107108
if(!$model) $model = $this->createModel();
108109

109110
// Set the username and password in case
110-
// of changes in active directory
111+
// of changes in active directory.
111112
$model->{$key} = $username;
112113

113-
// Sync the users password
114+
// Sync the users password.
114115
$model = $this->syncModelPassword($model, $password);
115116

116117
// Synchronize other active directory
117-
// attributes on the model
118+
// attributes on the model.
118119
$model = $this->syncModelFromAdldap($user, $model);
119120

120121
if($this->getBindUserToModel()) {
@@ -166,6 +167,16 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
166167
*/
167168
protected function syncModelPassword(Authenticatable $model, $password)
168169
{
170+
if ($model instanceof Model && $model->hasSetMutator('password')) {
171+
// If the model has a set mutator for the password then
172+
// we'll assume that the dev is using they're
173+
// own encryption method for passwords.
174+
$model->password = $password;
175+
176+
return $model;
177+
}
178+
179+
// Always encrypt the model password by default.
169180
$model->password = bcrypt($password);
170181

171182
return $model;

0 commit comments

Comments
 (0)