Skip to content

Beautiful Open-Source Form Builder

Enhance password security and user experience in authentication forms (#902)

Chirag Chhatrala18369cb7978b
diff --git a/api/app/Http/Controllers/Auth/RegisterController.php b/api/app/Http/Controllers/Auth/RegisterController.php
index 7a964ceb4..9e5e25788 100644
--- a/api/app/Http/Controllers/Auth/RegisterController.php
+++ b/api/app/Http/Controllers/Auth/RegisterController.php
@@ -70,7 +70,15 @@ class RegisterController extends Controller
$rules = [
'name' => 'required|max:255',
'email' => 'required|email:filter|max:255|unique:users|indisposable',
- 'password' => 'required|min:6|confirmed',
+ 'password' => [
+ 'required',
+ 'string',
+ 'min:8', // Minimum password length
+ 'regex:/[A-Za-z]/', // Include letters
+ 'regex:/[0-9]/', // Include numbers
+ 'regex:/[@$!%*#?&\-_+=.,:;<>^()[\]{}|~]/', // Include special characters (expanded set)
+ 'confirmed',
+ ],
'hear_about_us' => 'required|string',
'appsumo_license' => ['nullable'],
'invite_token' => ['nullable', 'string'],
diff --git a/api/app/Http/Controllers/Settings/PasswordController.php b/api/app/Http/Controllers/Settings/PasswordController.php
index 74a7a20fe..fc71240c9 100644
--- a/api/app/Http/Controllers/Settings/PasswordController.php
+++ b/api/app/Http/Controllers/Settings/PasswordController.php
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Validation\ValidationException;
class PasswordController extends Controller
{
@@ -15,9 +17,25 @@ class PasswordController extends Controller
public function update(Request $request)
{
$this->validate($request, [
- 'password' => 'required|confirmed|min:6',
+ 'current_password' => 'required',
+ 'password' => [
+ 'required',
+ 'string',
+ 'min:8', // Minimum password length
+ 'regex:/[A-Za-z]/', // Include letters
+ 'regex:/[0-9]/', // Include numbers
+ 'regex:/[@$!%*#?&\-_+=.,:;<>^()[\]{}|~]/', // Include special characters (expanded set)
+ 'confirmed',
+ ],
]);
+ // Verify current password matches
+ if (!Hash::check($request->current_password, $request->user()->password)) {
+ throw ValidationException::withMessages([
+ 'current_password' => ['The current password is incorrect.'],
+ ]);
+ }
+
$request->user()->update([
'password' => bcrypt($request->password),
]);
diff --git a/api/database/factories/UserFactory.php b/api/database/factories/UserFactory.php
index dda03c49e..184e23f71 100644
--- a/api/database/factories/UserFactory.php
+++ b/api/database/factories/UserFactory.php
@@ -27,7 +27,7 @@ class UserFactory extends Factory
'email' => $this->faker->unique()->safeEmail,
'hear_about_us' => 'google',
'email_verified_at' => now(),
- 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
+ 'password' => '$2y$10$Ey6obpHoTtSrMqGYjXf7Uu21i.pUqNy/rcG6etOAnKxtYCZmMHC1.', // Abcd@1234
'remember_token' => Str::random(10),
];
}
diff --git a/api/tests/Browser/LoginTest.php b/api/tests/Browser/LoginTest.php
index 0f58b81ab..8e0134240 100644
--- a/api/tests/Browser/LoginTest.php
+++ b/api/tests/Browser/LoginTest.php
@@ -13,7 +13,7 @@ it('can login onboarded users', function () {
$this->browse(function ($browser) use ($user) {
$browser->visit(new Login())
- ->submit($user->email, 'password')
+ ->submit($user->email, 'Abcd@1234')
->assertPageIs(Home::class);
});
});
@@ -32,7 +32,7 @@ it('can log out the user', function () {
$this->browse(function ($browser) use ($user) {
$browser->visit(new Login())
- ->submit($user->email, 'password')
+ ->submit($user->email, 'Abcd@1234')
->on(new Home())
->clickLogout()
->assertPageIs(Login::class);
diff --git a/api/tests/Browser/RegisterTest.php b/api/tests/Browser/RegisterTest.php
index 0f6c94f5e..af1d97ddd 100644
--- a/api/tests/Browser/RegisterTest.php
+++ b/api/tests/Browser/RegisterTest.php
@@ -44,8 +44,8 @@ class RegisterTest extends DuskTestCase
$browser->submit([
'name' => 'Test User',
'email' => '[email protected]',
- 'password' => 'password',
- 'password_confirmation' => 'password',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
])
->assertPageIs(Onboarding::class);
});
@@ -62,8 +62,8 @@ class RegisterTest extends DuskTestCase
$browser->submit([
'name' => 'Test User',
'email' => $user->email,
- 'password' => 'password',
- 'password_confirmation' => 'password',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
])
->pause(3000)
->assertSee('The email has already been taken.');
diff --git a/api/tests/Feature/LoginTest.php b/api/tests/Feature/LoginTest.php
index 64f0ccc55..f2727ab6f 100644
--- a/api/tests/Feature/LoginTest.php
+++ b/api/tests/Feature/LoginTest.php
@@ -7,7 +7,7 @@ it('can login to Forms', function () {
$this->postJson('/login', [
'email' => $user->email,
- 'password' => 'password',
+ 'password' => 'Abcd@1234',
])
->assertSuccessful()
->assertJsonStructure(['token', 'expires_in'])
@@ -24,7 +24,7 @@ it('can fetch current user', function () {
it('can log out', function () {
$this->postJson('/login', [
'email' => User::factory()->create()->email,
- 'password' => 'password',
+ 'password' => 'Abcd@1234',
])->assertSuccessful();
$this->assertAuthenticated();
@@ -43,7 +43,7 @@ it('cannot login if user is blocked', function () {
$this->postJson('/login', [
'email' => $user->email,
- 'password' => 'password',
+ 'password' => 'Abcd@1234',
])
->assertStatus(422)
->assertJsonValidationErrors(['email' => 'Your account has been blocked. Please contact support.']);
diff --git a/api/tests/Feature/RegisterTest.php b/api/tests/Feature/RegisterTest.php
index fe0eafa1f..800396614 100644
--- a/api/tests/Feature/RegisterTest.php
+++ b/api/tests/Feature/RegisterTest.php
@@ -14,8 +14,8 @@ it('can register', function () {
'name' => 'Test User',
'email' => '[email protected]',
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'g-recaptcha-response' => 'test-token', // Mock token for testing
])
@@ -44,8 +44,8 @@ it('cannot register with existing email', function () {
$this->postJson('/register', [
'name' => 'Test User',
'email' => '[email protected]',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'g-recaptcha-response' => 'test-token',
])
->assertStatus(422)
@@ -69,8 +69,8 @@ it('cannot register with disposable email', function () {
'name' => 'Test disposable',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'g-recaptcha-response' => 'test-token',
])
@@ -97,8 +97,8 @@ it('requires hcaptcha token in production', function () {
'name' => 'Test User',
'email' => '[email protected]',
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
])
->assertStatus(422)
diff --git a/api/tests/Feature/SettingsTest.php b/api/tests/Feature/SettingsTest.php
index b9b86bc4c..be7376489 100644
--- a/api/tests/Feature/SettingsTest.php
+++ b/api/tests/Feature/SettingsTest.php
@@ -22,10 +22,11 @@ it('update profile info', function () {
it('update password', function () {
$this->actingAs($user = User::factory()->create())
->patchJson('/settings/password', [
- 'password' => 'updated',
- 'password_confirmation' => 'updated',
+ 'current_password' => 'Abcd@1234',
+ 'password' => 'Abcd@1234_updated',
+ 'password_confirmation' => 'Abcd@1234_updated',
])
->assertSuccessful();
- $this->assertTrue(Hash::check('updated', $user->password));
+ $this->assertTrue(Hash::check('Abcd@1234_updated', $user->password));
});
diff --git a/api/tests/Feature/UserManagementTest.php b/api/tests/Feature/UserManagementTest.php
index b49eb3372..c9db446ea 100644
--- a/api/tests/Feature/UserManagementTest.php
+++ b/api/tests/Feature/UserManagementTest.php
@@ -34,8 +34,8 @@ it('can register with invite token', function () {
'name' => 'Invitee',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'invite_token' => $token,
'h-captcha-response' => 'test-token',
@@ -64,8 +64,8 @@ it('cannot register with expired invite token', function () {
'name' => 'Invitee',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'invite_token' => $token,
'h-captcha-response' => 'test-token',
@@ -95,8 +95,8 @@ it('cannot re-register with accepted invite token', function () {
'name' => 'Invitee',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'invite_token' => $token,
'h-captcha-response' => 'test-token',
@@ -113,8 +113,8 @@ it('cannot re-register with accepted invite token', function () {
'name' => 'Invitee',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'invite_token' => $token,
'h-captcha-response' => 'test-token',
@@ -149,8 +149,8 @@ it('can cancel user invite', function () {
'name' => 'Invitee',
'email' => $email,
'hear_about_us' => 'google',
- 'password' => 'secret',
- 'password_confirmation' => 'secret',
+ 'password' => 'Abcd@1234',
+ 'password_confirmation' => 'Abcd@1234',
'agree_terms' => true,
'invite_token' => $token,
'h-captcha-response' => 'test-token',
diff --git a/api/tests/TestHelpers.php b/api/tests/TestHelpers.php
index ccc7448c8..68951ea54 100644
--- a/api/tests/TestHelpers.php
+++ b/api/tests/TestHelpers.php
@@ -214,7 +214,7 @@ trait TestHelpers
$this->postJson('/login', [
'email' => $user->email,
- 'password' => 'password',
+ 'password' => 'Abcd@1234',
])->assertSuccessful();
return $user;
diff --git a/client/components/pages/auth/PasswordStrengthIndicator.vue b/client/components/pages/auth/PasswordStrengthIndicator.vue
new file mode 100644
index 000000000..15bc7a0d5
--- /dev/null
+++ b/client/components/pages/auth/PasswordStrengthIndicator.vue
@@ -0,0 +1,125 @@
+<template>
+ <div class="mt-2 space-y-2">
+ <!-- Strength Bar -->
+ <div class="flex items-center gap-2">
+ <span class="text-xs font-medium text-neutral-600">Password Strength:</span>
+ <div class="flex-1 bg-neutral-200 rounded-full h-2 max-w-32">
+ <div
+ class="h-2 rounded-full transition-all duration-300"
+ :class="strengthBarClass"
+ :style="{ width: strengthPercentage + '%' }"
+ ></div>
+ </div>
+ <span class="text-xs font-medium" :class="strengthTextClass">
+ {{ strengthText }}
+ </span>
+ </div>
+
+ <!-- Password Rules -->
+ <div class="space-y-1">
+ <div class="grid grid-cols-2 gap-1">
+ <div
+ v-for="rule in passwordRulesConfig"
+ :key="rule.key"
+ class="flex items-center gap-1"
+ >
+ <Icon
+ :name="passwordRules[rule.key] ? 'heroicons:check-circle' : 'heroicons:x-circle'"
+ :class="passwordRules[rule.key] ? 'text-green-500' : 'text-neutral-400'"
+ class="w-3 h-3"
+ />
+ <span class="text-xs" :class="passwordRules[rule.key] ? 'text-green-600' : 'text-neutral-500'">
+ {{ rule.message }}
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup>
+// Props
+const props = defineProps({
+ password: {
+ type: String,
+ default: ''
+ }
+})
+
+// Password rules configuration
+const passwordRulesConfig = [
+ {
+ key: 'minLength',
+ message: '8 characters minimum',
+ validator: (password) => password.length >= 8
+ },
+ {
+ key: 'hasLetter',
+ message: '1 letter',
+ validator: (password) => /[A-Za-z]/.test(password)
+ },
+ {
+ key: 'hasNumber',
+ message: '1 number',
+ validator: (password) => /[0-9]/.test(password)
+ },
+ {
+ key: 'hasSpecial',
+ message: '1 special character',
+ validator: (password) => /[@$!%*#?&]/.test(password)
+ }
+]
+
+// Password strength validation
+const passwordRules = computed(() => {
+ const password = props.password || ''
+ const rules = {}
+
+ passwordRulesConfig.forEach(rule => {
+ rules[rule.key] = rule.validator(password)
+ })
+
+ return rules
+})
+
+// Calculate password strength
+const passwordStrength = computed(() => {
+ const rules = passwordRules.value
+ const passedRules = Object.values(rules).filter(Boolean).length
+ return passedRules
+})
+
+// Strength percentage for progress bar
+const strengthPercentage = computed(() => {
+ return (passwordStrength.value / passwordRulesConfig.length) * 100
+})
+
+// Strength configuration
+const strengthConfig = [
+ { threshold: 0, text: 'Very Weak', barClass: 'bg-neutral-300', textClass: 'text-neutral-500' },
+ { threshold: 1, text: 'Weak', barClass: 'bg-red-500', textClass: 'text-red-600' },
+ { threshold: 2, text: 'Fair', barClass: 'bg-orange-500', textClass: 'text-orange-600' },
+ { threshold: 3, text: 'Good', barClass: 'bg-yellow-500', textClass: 'text-yellow-600' },
+ { threshold: passwordRulesConfig.length, text: 'Strong', barClass: 'bg-green-500', textClass: 'text-green-600' }
+]
+
+// Strength bar styling
+const strengthBarClass = computed(() => {
+ const strength = passwordStrength.value
+ const config = strengthConfig.find(config => strength <= config.threshold) || strengthConfig[strengthConfig.length - 1]
+ return config.barClass
+})
+
+// Strength text and styling
+const strengthText = computed(() => {
+ const strength = passwordStrength.value
+ const config = strengthConfig.find(config => strength <= config.threshold) || strengthConfig[strengthConfig.length - 1]
+ return config.text
+})
+
+const strengthTextClass = computed(() => {
+ const strength = passwordStrength.value
+ const config = strengthConfig.find(config => strength <= config.threshold) || strengthConfig[strengthConfig.length - 1]
+ return config.textClass
+})
+</script>
diff --git a/client/components/pages/auth/components/RegisterForm.vue b/client/components/pages/auth/components/RegisterForm.vue
index 8463f74cf..f13adddbf 100644
--- a/client/components/pages/auth/components/RegisterForm.vue
+++ b/client/components/pages/auth/components/RegisterForm.vue
@@ -41,6 +41,12 @@
:form="form"
label="Password"
:required="true"
+ @focus="isPasswordFocused = true"
+ @blur="isPasswordFocused = false"
+ />
+ <PasswordStrengthIndicator
+ v-show="isPasswordFocused"
+ :password="form.password"
/>
<!-- Password Confirmation-->
@@ -194,6 +200,9 @@ const form = useForm({
const disableEmail = ref(false)
const captcha = ref(null)
+// Password field focus state
+const isPasswordFocused = ref(false)
+
// Computed
const reCaptchaSiteKey = computed(() => {
return runtimeConfig.public.reCaptchaSiteKey
diff --git a/client/components/users/settings/Security.vue b/client/components/users/settings/Security.vue
index 3db803c73..173522d8f 100644
--- a/client/components/users/settings/Security.vue
+++ b/client/components/users/settings/Security.vue
@@ -14,16 +14,31 @@
@submit.prevent="updatePassword"
>
<div class="max-w-sm">
- <text-input
+ <TextInput
+ :form="passwordForm"
+ name="current_password"
+ label="Current Password"
+ native-type="password"
+ placeholder="Enter current password"
+ :required="true"
+ />
+
+ <TextInput
:form="passwordForm"
name="password"
label="New Password"
native-type="password"
placeholder="Enter new password"
:required="true"
+ @focus="isPasswordFocused = true"
+ @blur="isPasswordFocused = false"
+ />
+ <PasswordStrengthIndicator
+ v-show="isPasswordFocused"
+ :password="passwordForm.password"
/>
- <text-input
+ <TextInput
:form="passwordForm"
name="password_confirmation"
label="Confirm Password"
@@ -73,10 +88,14 @@ const alert = useAlert()
// Password form
const passwordForm = useForm({
+ current_password: '',
password: '',
password_confirmation: ''
})
+// Password field focus state
+const isPasswordFocused = ref(false)
+
// Update password
const updatePassword = () => {
passwordForm