mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fix generated password validation
This commit is contained in:
@@ -8,6 +8,10 @@ describe('Password validation utils', () => {
|
||||
it('Accepts correct password with symbols', () => {
|
||||
expect(validatePassword('thisisav~!%ali&dpas$sword').isValid).toBeTruthy()
|
||||
})
|
||||
it('Accepts generated password symbols', () => {
|
||||
expect(validatePassword('valid^password').isValid).toBeTruthy()
|
||||
expect(validatePassword('valid?password').isValid).toBeTruthy()
|
||||
})
|
||||
it('Rejects invalid password with unsupported symbols in the middle', () => {
|
||||
expect(validatePassword('thisisav~%a€li&dpas$sword').isValid).toBeFalsy()
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ export interface PasswordValidationResult {
|
||||
|
||||
export const validatePassword = (password: string): PasswordValidationResult => {
|
||||
if (password.length < 8) return { isValid: false, error: 'Password must be at least 8 characters long' }
|
||||
if (!/^[0-9A-Za-z$%&~!]+$/.test(password))
|
||||
if (!/^[0-9A-Za-z^?$%&~!]+$/.test(password))
|
||||
return {
|
||||
isValid: false,
|
||||
error: 'Password must only contain characters a-z, A-Z, 0-9 and ^?$%&~!',
|
||||
|
||||
@@ -19,7 +19,7 @@ export const usePasswordValidation = () => {
|
||||
return { isValid: false, error: requirements[0] }
|
||||
}
|
||||
|
||||
if (!/^[0-9A-Za-z$%&~!]+$/.test(password)) {
|
||||
if (!/^[0-9A-Za-z^?$%&~!]+$/.test(password)) {
|
||||
return { isValid: false, error: requirements[1] }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user