Merge pull request 'Issue 20 : fix enforce password special character validation and disallow whitespace as special character' (#25) from fix/issue-20-password-special-character-validation into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/25
This commit is contained in:
Amit Salunke 2026-10-06 12:18:58 +00:00
commit a1e687154d
2 changed files with 27 additions and 3 deletions

View File

@ -299,6 +299,30 @@ export default function App() {
setAuthError(null);
const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register';
if (authMode === 'register') {
if (authPassword.length < 8) {
setAuthError('Password must be at least 8 characters long.');
setAuthLoading(false);
return;
}
if (!/[A-Z]/.test(authPassword)) {
setAuthError('Password must contain at least one uppercase letter.');
setAuthLoading(false);
return;
}
if (!/[0-9]/.test(authPassword)) {
setAuthError('Password must contain at least one number.');
setAuthLoading(false);
return;
}
if (!/[^A-Za-z0-9\s]/.test(authPassword)) {
setAuthError('Password must contain at least one special character.');
setAuthLoading(false);
return;
}
}
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
const payload = authMode === 'login'
? { email: authEmail, password: authPassword }
@ -352,7 +376,7 @@ export default function App() {
setChangePasswordError('New password must contain at least one number.');
return;
}
if (!/[^A-Za-z0-9]/.test(changeNewPassword)) {
if (!/[^A-Za-z0-9\s]/.test(changeNewPassword)) {
setChangePasswordError('New password must contain at least one special character.');
return;
}
@ -423,7 +447,7 @@ export default function App() {
setAuthLoading(false);
return;
}
if (!/[^A-Za-z0-9]/.test(resetNewPassword)) {
if (!/[^A-Za-z0-9\s]/.test(resetNewPassword)) {
setAuthError('New password must contain at least one special character.');
setAuthLoading(false);
return;

View File

@ -285,7 +285,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
<span className={/[0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
&bull; 1 number
</span>
<span className={/[^A-Za-z0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
<span className={/[^A-Za-z0-9\s]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
&bull; 1 special char
</span>
</div>