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

Commit aa12405

Browse files
committed
Make sure passwords aren't set upon every login
1 parent 9c8438c commit aa12405

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/Commands/SyncPassword.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ protected function applyPassword($password)
8484
*/
8585
protected function passwordNeedsUpdate($password = null) : bool
8686
{
87-
$current = $this->currentPassword();
87+
$current = $this->currentModelPassword();
8888

89-
return is_null($current) || ! Hash::check($password, $current);
89+
if ($this->canSync()) {
90+
return ! Hash::check($password, $current);
91+
}
92+
93+
return is_null($current);
9094
}
9195

9296
/**
@@ -116,7 +120,7 @@ protected function password()
116120
*
117121
* @return string|null
118122
*/
119-
protected function currentPassword()
123+
protected function currentModelPassword()
120124
{
121125
return $this->model->getAttribute($this->column());
122126
}

tests/DatabaseProviderTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function passwords_are_synced_when_enabled()
198198
}
199199

200200
/** @test */
201-
public function passwords_are_not_synced_when_enabled()
201+
public function passwords_are_not_synced_when_sync_is_disabled()
202202
{
203203
config(['adldap_auth.passwords.sync' => false]);
204204

@@ -215,6 +215,25 @@ public function passwords_are_not_synced_when_enabled()
215215
$this->assertFalse(Hash::check($credentials['password'], $user->password));
216216
}
217217

218+
/** @test */
219+
public function passwords_are_not_updated_when_sync_is_disabled()
220+
{
221+
config(['adldap_auth.passwords.sync' => false]);
222+
223+
$credentials = [
224+
'email' => '[email protected]',
225+
'password' => '12345',
226+
];
227+
228+
$this->auth_passes($credentials);
229+
230+
$user = EloquentUser::first();
231+
232+
$this->auth_passes($credentials);
233+
234+
$this->assertEquals($user->password, $user->fresh()->password);
235+
}
236+
218237
/** @test */
219238
public function trashed_rule_prevents_deleted_users_from_logging_in()
220239
{

0 commit comments

Comments
 (0)