-
Notifications
You must be signed in to change notification settings - Fork 0
feat: when login, add passsword leaked warning for the user to change… #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||
|
||||||||
use Illuminate\Auth\Events\Lockout; | ||||||||
use Illuminate\Support\Facades\Auth; | ||||||||
use Illuminate\Support\Facades\Http; | ||||||||
use Illuminate\Support\Facades\RateLimiter; | ||||||||
use Illuminate\Support\Facades\Route; | ||||||||
use Illuminate\Support\Facades\Session; | ||||||||
|
@@ -40,6 +41,11 @@ public function login(): void | |||||||
RateLimiter::clear($this->throttleKey()); | ||||||||
Session::regenerate(); | ||||||||
|
||||||||
if ($this->isPasswordPwned($this->password)) { | ||||||||
// Flash a warning message after successful login | ||||||||
session()->flash('password_breach_warning', '⚠️ Your password has appeared in a data breach. For your safety, please change it soon.'); | ||||||||
} | ||||||||
|
||||||||
$this->redirectIntended(default: route('home', absolute: false), navigate: true); | ||||||||
} | ||||||||
|
||||||||
|
@@ -71,6 +77,39 @@ protected function throttleKey(): string | |||||||
{ | ||||||||
return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); | ||||||||
} | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
protected function isPasswordPwned(string $password): bool | ||||||||
{ | ||||||||
$sha1 = strtoupper(sha1($password)); | ||||||||
$prefix = substr($sha1, 0, 5); | ||||||||
$suffix = substr($sha1, 5); | ||||||||
|
||||||||
$response = Http::get("https://api.pwnedpasswords.com/range/{$prefix}"); | ||||||||
if ($response->failed()) { | ||||||||
return false; // fail-safe | ||||||||
} | ||||||||
|
||||||||
foreach (explode("\n", $response->body()) as $line) { | ||||||||
[$hashSuffix, $count] = explode(':', $line); | ||||||||
if ($suffix === trim($hashSuffix)) { | ||||||||
return true; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
Comment on lines
+113
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the excessive blank lines (lines 104-112) at the end of the class to maintain consistent code formatting.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
+114
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excessive blank lines after the method. Remove unnecessary empty lines to maintain consistent code formatting.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
+114
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the excessive blank lines at the end of the function. Use consistent spacing with at most one blank line.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
}; ?> | ||||||||
|
||||||||
<div class="flex flex-col gap-6"> | ||||||||
|
@@ -79,11 +118,13 @@ protected function throttleKey(): string | |||||||
<p class="mt-1 text-sm text-base-content/70">{{ __('Enter your email and password below to log in') }}</p> | ||||||||
</div> | ||||||||
|
||||||||
@if (session('status')) | ||||||||
<x-mary-alert color="info" class="text-center"> | ||||||||
{{ session('status') }} | ||||||||
</x-mary-alert> | ||||||||
@endif | ||||||||
@if (session('status')) | ||||||||
<x-mary-alert color="warning" class="text-center"> | ||||||||
{{ session('status') }} | ||||||||
</x-mary-alert> | ||||||||
@endif | ||||||||
|
||||||||
|
||||||||
|
||||||||
Comment on lines
+136
to
137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the trailing whitespace on line 127 and the unnecessary blank line 128 to maintain clean formatting.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
<form method="POST" wire:submit="login" class="flex flex-col gap-6"> | ||||||||
<x-mary-input | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the excessive blank lines (lines 80-83) before the
isPasswordPwned
method to maintain consistent code formatting.Copilot uses AI. Check for mistakes.