-
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 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -170,6 +170,74 @@ class="w-10 h-10 rounded-full bg-primary text-primary-content flex items-center | |||||
</div> | ||||||
</header> | ||||||
|
||||||
|
||||||
<!-- Password Breach Warning Alert --> | ||||||
<!-- Password Breach Warning Alert --> | ||||||
@if ( session('password_breach_warning')) | ||||||
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 unnecessary space after the opening parenthesis. Should be
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
<!-- Inline alert for desktop --> | ||||||
<div class="hidden sm:block"> | ||||||
<x-mary-alert | ||||||
title="Warning {{ session('password_breach_warning') }}" | ||||||
icon="o-exclamation-triangle" | ||||||
dismissible | ||||||
class="alert-warning px-42 text-lg" | ||||||
x-data="{ show: true }" | ||||||
x-show="show" | ||||||
> | ||||||
<x-slot:actions> | ||||||
<a href="{{ route('settings.password') }}" @click="show = false"> | ||||||
<x-mary-button label="Change password" class="btn-warning btn-soft"/> | ||||||
</a> | ||||||
</x-slot:actions> | ||||||
</x-mary-alert> | ||||||
</div> | ||||||
|
||||||
<!-- Mobile popup alert --> | ||||||
<div class="sm:hidden" x-data="{ open: true }" x-show="open"> | ||||||
<!-- Full-screen dark overlay --> | ||||||
<div | ||||||
class="fixed inset-0 bg-black/70 z-40" | ||||||
@click="open = false" | ||||||
></div> | ||||||
|
||||||
<!-- Modal --> | ||||||
<div class="fixed inset-0 flex items-center justify-center z-50 px-4"> | ||||||
<div class="bg-base-100 rounded-lg w-full max-w-sm p-6 relative shadow-lg"> | ||||||
|
||||||
<!-- Close button --> | ||||||
<!-- Close button --> | ||||||
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. Duplicate comment. Remove one of the redundant 'Close button' comments.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
<button | ||||||
@click="open = false" | ||||||
class="absolute top-3 right-3 text-gray-800 hover:text-gray-900 text-3xl font-bold" | ||||||
aria-label="Close" | ||||||
> | ||||||
× | ||||||
</button> | ||||||
|
||||||
|
||||||
<!-- Warning message --> | ||||||
<div class="mb-6 flex flex-col items-center text-center gap-2"> | ||||||
<x-mary-icon name="o-exclamation-triangle" class="h-8 w-8 "/> | ||||||
<span class="font-medium content"> | ||||||
Warning: {{ session('password_breach_warning') }} | ||||||
</span> | ||||||
</div> | ||||||
|
||||||
<!-- Change password button --> | ||||||
<a href="{{ route('settings.password') }}" @click="open = false"> | ||||||
<x-mary-button label="Change password" class="btn-warning btn-soft w-full"/> | ||||||
</a> | ||||||
</div> | ||||||
</div> | ||||||
</div> | ||||||
|
||||||
|
||||||
@endif | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
<!-- Main Content --> | ||||||
<main class="min-h-screen"> | ||||||
{{ $slot }} | ||||||
|
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.'); | ||||||||||||||
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. The error message has an extra space at the beginning. Remove the leading space before 'Your password'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$this->redirectIntended(default: route('home', absolute: false), navigate: true); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -71,6 +77,44 @@ protected function throttleKey(): string | |||||||||||||
{ | ||||||||||||||
return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
Comment on lines
+81
to
+83
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 80-83) before the
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
protected function isPasswordPwned(string $password): bool | ||||||||||||||
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. Inconsistent indentation. The method signature should align with other methods in the class (no leading spaces).
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
{ | ||||||||||||||
$sha1 = strtoupper(sha1($password)); | ||||||||||||||
$prefix = substr($sha1, 0, 5); | ||||||||||||||
$suffix = substr($sha1, 5); | ||||||||||||||
|
||||||||||||||
$response = Http::get("https://api.pwnedpasswords.com/range/{$prefix}"); | ||||||||||||||
|
$response = Http::get("https://api.pwnedpasswords.com/range/{$prefix}"); | |
try { | |
$response = Http::timeout(2)->get("https://api.pwnedpasswords.com/range/{$prefix}"); | |
} catch (\Exception $e) { | |
return false; // fail-safe on timeout or connection error | |
} |
Copilot uses AI. Check for mistakes.
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 104-112) at the end of the class to maintain consistent code formatting.
Copilot uses AI. Check for mistakes.
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.
Excessive blank lines after the method. Remove unnecessary empty lines to maintain consistent code formatting.
Copilot uses AI. Check for mistakes.
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 at the end of the function. Use consistent spacing with at most one blank line.
Copilot uses AI. Check for mistakes.
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 trailing whitespace on line 127 and the unnecessary blank line 128 to maintain clean formatting.
Copilot uses AI. Check for mistakes.
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.
Duplicate comment. The comment on line 174 and 175 are redundant.
Copilot uses AI. Check for mistakes.