Skip to content

Commit

Permalink
LP-3 fix: wrong password and threshold count failed messaged fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Oct 1, 2023
1 parent 0ebc002 commit 992dd1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/Http/Controllers/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,31 @@ public function store(LoginRequest $request): LoginResource|JsonResponse
if ($attemptUser->wrong_password > config('fintech.auth.threshold.password', 10)) {

\Fintech\Auth\Facades\Auth::user()->update($attemptUser->id, [
'status' => UserStatus::InActive->value,
'status' => UserStatus::InActive->value
]);

return $this->failed(__('auth::messages.lockup'));
}

if (! Hash::check($request->input('password'), $attemptUser->password)) {
if (!Hash::check($request->input('password'), $attemptUser->password)) {

$request->hitRateLimited();

$wrongPasswordCount = $attemptUser->wrong_password + 1;
\Fintech\Auth\Facades\Auth::user()->update($attemptUser->id, [
'wrong_password' => $attemptUser->wrong_password + 1,
'wrong_password' => $wrongPasswordCount,
]);

return $this->failed(__('auth::messages.failed'));
return $this->failed(__('auth::messages.warning', [
'attempt' => $wrongPasswordCount,
'threshold' => config('fintech.auth.threshold.password', 10)
]));
}

$request->clearRateLimited();

Auth::login($attemptUser);

Auth::user()->tokens->each(fn ($token) => $token->delete());
Auth::user()->tokens->each(fn($token) => $token->delete());

Check failure on line 67 in src/Http/Controllers/AuthenticatedSessionController.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Illuminate\Foundation\Auth\User::$tokens.

//permission check

Expand Down
6 changes: 6 additions & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class User extends Authenticatable implements Auditable
protected $casts = [
'email_verified_at' => 'datetime',
'mobile_verified_at' => 'datetime',
'wrong_password' => 'integer'
];

protected $attributes = [
'wrong_password' => 0,
'wrong_pin' => 0,
];

/*
Expand Down
4 changes: 2 additions & 2 deletions src/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public function read($id)

public function update($id, array $inputs = [])
{
if ($inputs['password']) {
if (isset($inputs['password']) && !empty($inputs['password'])) {
$inputs['password'] = Hash::make($inputs['password']);
}
if ($inputs['pin']) {
if (isset($inputs['pin']) && !empty($inputs['pin'])) {
$inputs['pin'] = Hash::make($inputs['pin']);
}

Expand Down

0 comments on commit 992dd1a

Please sign in to comment.