Add password confirmation, validation, and email notification for password changes

This commit is contained in:
pacnpal
2024-11-13 15:17:07 +00:00
parent 5a1fdb6d16
commit 1ee4b00961
3 changed files with 134 additions and 5 deletions

View File

@@ -45,7 +45,17 @@
</div>
<div class="p-6 mt-6 overflow-hidden bg-white rounded-lg shadow dark:bg-gray-800">
<form method="POST">
<form method="POST" x-data="{
newPassword: '',
confirmPassword: '',
passwordsMatch() { return this.newPassword === this.confirmPassword },
isValidPassword() {
return this.newPassword.length >= 8 &&
/[A-Z]/.test(this.newPassword) &&
/[a-z]/.test(this.newPassword) &&
/[0-9]/.test(this.newPassword);
}
}">
{% csrf_token %}
<input type="hidden" name="action" value="change_password">
@@ -53,15 +63,46 @@
<div class="mb-4">
<label for="old_password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Current Password</label>
<input type="password" name="old_password" id="old_password" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300">
<input type="password" name="old_password" id="old_password" required class="block w-full mt-1 border-gray-300 rounded-md shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300">
</div>
<div class="mb-4">
<label for="new_password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">New Password</label>
<input type="password" name="new_password" id="new_password" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300">
<input
type="password"
name="new_password"
id="new_password"
x-model="newPassword"
required
class="block w-full mt-1 border-gray-300 rounded-md shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300"
>
<div class="mt-1 text-sm text-gray-500 dark:text-gray-400" x-show="newPassword && !isValidPassword()">
Password must be at least 8 characters and contain uppercase, lowercase, and numbers
</div>
</div>
<button type="submit" class="px-4 py-2 text-white bg-blue-500 rounded-md">Change Password</button>
<div class="mb-4">
<label for="confirm_password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Confirm New Password</label>
<input
type="password"
name="confirm_password"
id="confirm_password"
x-model="confirmPassword"
required
class="block w-full mt-1 border-gray-300 rounded-md shadow-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300"
>
<div class="mt-1 text-sm text-red-500" x-show="confirmPassword && !passwordsMatch()">
Passwords do not match
</div>
</div>
<button
type="submit"
class="px-4 py-2 text-white bg-blue-500 rounded-md disabled:opacity-50"
x-bind:disabled="!passwordsMatch() || !isValidPassword()"
>
Change Password
</button>
</form>
</div>
</div>