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

Commit ae8defb

Browse files
committed
Don't update passwords in the Importer
- Closes #263
1 parent 93a7278 commit ae8defb

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

src/Auth/DatabaseUserProvider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ public function validateCredentials(Authenticatable $model, array $credentials)
135135
// validation rules pass, we will allow the authentication
136136
// attempt. Otherwise, it is automatically rejected.
137137
if ($this->newValidator($this->getRules($this->user, $model))->passes()) {
138+
// We'll check if we've been given a password and that
139+
// syncing password is enabled. Otherwise we'll
140+
// use a random 16 character string.
141+
if ($this->isSyncingPasswords()) {
142+
$password = $credentials['password'];
143+
} else {
144+
$password = str_random();
145+
}
146+
147+
// If the model has a set mutator for the password then we'll
148+
// assume that we're using a custom encryption method for
149+
// passwords. Otherwise we'll bcrypt it normally.
150+
$model->password = $model->hasSetMutator('password') ?
151+
$password : bcrypt($password);
152+
138153
// All of our validation rules have passed and we can
139154
// finally save the model in case of changes.
140155
$model->save();
@@ -198,6 +213,16 @@ class_uses_recursive(get_class($model))
198213
);
199214
}
200215

216+
/**
217+
* Determines if passwords are being syncronized.
218+
*
219+
* @return bool
220+
*/
221+
public function isSyncingPasswords()
222+
{
223+
return config('adldap_auth.password_sync', true);
224+
}
225+
201226
/**
202227
* Determines if login fallback is enabled.
203228
*

src/Auth/Importer.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ public function run(User $user, Model $model, array $credentials = [])
1919
// we'll create a new one for them.
2020
$model = $this->findByCredentials($model, $credentials) ?: $model->newInstance();
2121

22-
// We'll check if we've been given a password and that
23-
// syncing password is enabled. Otherwise we'll
24-
// use a random 16 character string.
25-
if (
26-
array_key_exists('password', $credentials) &&
27-
$this->isSyncingPasswords()
28-
) {
29-
$password = $credentials['password'];
30-
} else {
31-
$password = str_random();
32-
}
33-
34-
// If the model has a set mutator for the password then we'll
35-
// assume that we're using a custom encryption method for
36-
// passwords. Otherwise we'll bcrypt it normally.
37-
$model->password = $model->hasSetMutator('password') ?
38-
$password : bcrypt($password);
39-
4022
// Synchronize other LDAP attributes on the model.
4123
$this->syncModelAttributes($user, $model);
4224

@@ -101,16 +83,6 @@ protected function syncModelAttributes(User $user, Model $model)
10183
}
10284
}
10385

104-
/**
105-
* Returns the configured password sync configuration option.
106-
*
107-
* @return bool
108-
*/
109-
protected function isSyncingPasswords()
110-
{
111-
return config('adldap_auth.password_sync', true);
112-
}
113-
11486
/**
11587
* Retrieves the specified field from the User model.
11688
*

src/Commands/Import.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public function import(array $users = [])
106106
// Import the user and retrieve it's model.
107107
$model = $this->getImporter()->run($user, $this->model());
108108

109+
$password = str_random();
110+
111+
// Set the models password.
112+
$model->password = $model->hasSetMutator('password') ?
113+
$password : bcrypt($password);
114+
109115
// Save the returned model.
110116
$this->save($user, $model);
111117

src/Middleware/WindowsAuthenticate.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ protected function retrieveAuthenticatedUser($key, $username)
103103
// assigns a random 16 character password for us.
104104
$model = $this->getImporter()->run($user, $this->getModel(), $credentials);
105105

106+
$password = str_random();
107+
108+
// Set the models password.
109+
$model->password = $model->hasSetMutator('password') ?
110+
$password : bcrypt($password);
111+
106112
// We also want to save the returned model in case it doesn't
107113
// exist yet, or there are changes to be synced.
108114
$model->save();

0 commit comments

Comments
 (0)