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

Commit 36cc5ef

Browse files
authored
Merge pull request #449 from syphernl/fix/import_password
Fixes #448: Only generate a random password if we don't have one set
2 parents 65b6a5a + 8508930 commit 36cc5ef

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Auth/DatabaseUserProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,24 @@ public function validateCredentials(Authenticatable $model, array $credentials)
138138
// We'll check if we've been given a password and that
139139
// syncing password is enabled. Otherwise we'll
140140
// use a random 16 character string.
141+
142+
$password = null;
141143
if ($this->isSyncingPasswords()) {
142144
$password = $credentials['password'];
143145
} else {
144-
$password = str_random();
146+
if(null === $model->password || empty($model->password)) {
147+
// password unset
148+
$password = str_random();
149+
}
145150
}
146151

147152
// If the model has a set mutator for the password then we'll
148153
// assume that we're using a custom encryption method for
149154
// passwords. Otherwise we'll bcrypt it normally.
150-
$model->password = $model->hasSetMutator('password') ?
151-
$password : bcrypt($password);
155+
if(null !== $password) {
156+
$model->password = $model->hasSetMutator('password') ?
157+
$password : bcrypt($password);
158+
}
152159

153160
// All of our validation rules have passed and we can
154161
// finally save the model in case of changes.

src/Commands/Import.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ public function import(array $users = [])
112112
// Import the user and retrieve it's model.
113113
$model = $this->getImporter()->run($user, $this->model(), $credentials);
114114

115-
$password = str_random();
115+
// Only set a new password if we are creating a new user
116+
if (!isset($model->password) || empty($model->password)) {
117+
$password = str_random();
116118

117-
// Set the models password.
118-
$model->password = $model->hasSetMutator('password') ?
119-
$password : bcrypt($password);
119+
// Set the models password.
120+
$model->password = $model->hasSetMutator('password') ?
121+
$password : bcrypt($password);
122+
}
120123

121124
// Save the returned model.
122125
$this->save($user, $model);

0 commit comments

Comments
 (0)