From 76755041ab00a5c19ac27b543c84bc0c4ea58a01 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 3 Oct 2026 11:36:13 +0530 Subject: [PATCH] fix(auth): reject password with spaces and require special characters (#46) --- src/app/login/forgot-password.tsx | 5 ++++- src/app/profile/change-password.tsx | 5 ++++- src/features/auth/components/LoginForm.tsx | 3 +++ src/features/auth/components/SignUpForm.tsx | 5 ++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/login/forgot-password.tsx b/src/app/login/forgot-password.tsx index ec648f7..098228b 100644 --- a/src/app/login/forgot-password.tsx +++ b/src/app/login/forgot-password.tsx @@ -80,13 +80,16 @@ export default function ForgotPasswordScreen() { } else if (newPassword.length < 8) { setPasswordError("Must be at least 8 characters"); hasError = true; + } else if (/\s/.test(newPassword)) { + setPasswordError("Password must not contain spaces"); + hasError = true; } else if (!/[A-Z]/.test(newPassword)) { setPasswordError("Must contain at least one uppercase letter"); hasError = true; } else if (!/[0-9]/.test(newPassword)) { setPasswordError("Must contain at least one number"); hasError = true; - } else if (!/[^A-Za-z0-9]/.test(newPassword)) { + } else if (!/[^A-Za-z0-9\s]/.test(newPassword)) { setPasswordError("Must contain at least one special character"); hasError = true; } diff --git a/src/app/profile/change-password.tsx b/src/app/profile/change-password.tsx index 6a39621..5d82ba6 100644 --- a/src/app/profile/change-password.tsx +++ b/src/app/profile/change-password.tsx @@ -45,13 +45,16 @@ export default function ChangePasswordScreen() { } else if (newPassword.length < 8) { setNewError("New password must be at least 8 characters"); hasError = true; + } else if (/\s/.test(newPassword)) { + setNewError("Password must not contain spaces"); + hasError = true; } else if (!/[A-Z]/.test(newPassword)) { setNewError("Must contain at least one uppercase letter"); hasError = true; } else if (!/[0-9]/.test(newPassword)) { setNewError("Must contain at least one number"); hasError = true; - } else if (!/[^A-Za-z0-9]/.test(newPassword)) { + } else if (!/[^A-Za-z0-9\s]/.test(newPassword)) { setNewError("Must contain at least one special character"); hasError = true; } diff --git a/src/features/auth/components/LoginForm.tsx b/src/features/auth/components/LoginForm.tsx index 0dd5575..77d73af 100644 --- a/src/features/auth/components/LoginForm.tsx +++ b/src/features/auth/components/LoginForm.tsx @@ -71,6 +71,9 @@ export default function LoginForm({ if (!password) { setPasswordError("Password is required"); hasError = true; + } else if (/\s/.test(password)) { + setPasswordError("Password must not contain spaces"); + hasError = true; } if (hasError) return; diff --git a/src/features/auth/components/SignUpForm.tsx b/src/features/auth/components/SignUpForm.tsx index 406b04f..fbe8f69 100644 --- a/src/features/auth/components/SignUpForm.tsx +++ b/src/features/auth/components/SignUpForm.tsx @@ -63,13 +63,16 @@ export default function SignUpForm() { } else if (password.length < 8) { setPasswordError("Password must be at least 8 characters"); hasError = true; + } else if (/\s/.test(password)) { + setPasswordError("Password must not contain spaces"); + hasError = true; } else if (!/[A-Z]/.test(password)) { setPasswordError("Password must contain at least one uppercase letter (A-Z)"); hasError = true; } else if (!/[0-9]/.test(password)) { setPasswordError("Password must contain at least one number (0-9)"); hasError = true; - } else if (!/[^A-Za-z0-9]/.test(password)) { + } else if (!/[^A-Za-z0-9\s]/.test(password)) { setPasswordError("Password must contain at least one special character (!@#$)"); hasError = true; } -- 2.34.1