mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-23 14:17:06 +00:00
fix(gui): password strength check counts any symbol, punctuation, or space as a special character
A password whose only special character was ~, a backtick, a space, or a non-ASCII symbol such as € was rejected as having none.
This commit is contained in:
1 parent
9b64d44d5f
commit
490abccd6d
2 files changed
+32
-1
No files matched your search
@@ -24,7 +24,7 @@ const check_password_strength = (password) => {
|
||||
hasUpperCase: /[A-Z]/.test(password),
|
||||
hasLowerCase: /[a-z]/.test(password),
|
||||
hasNumber: /\d/.test(password),
|
||||
hasSpecialChar: /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password),
|
||||
hasSpecialChar: /[\p{P}\p{S}\s]/u.test(password),
|
||||
};
|
||||
|
||||
let overallPass = true;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import check_password_strength from './checkPasswordStrength.js';
|
||||
|
||||
describe('check_password_strength', () => {
|
||||
it('passes a password that meets every criterion', () => {
|
||||
expect(check_password_strength('Abcdefg1!').overallPass).toBe(true);
|
||||
});
|
||||
|
||||
it.each(['Abcdefg1~', 'Abcdefg1`', 'Abcdefg 1', 'Abcdefg1€', 'Abcdefg1£'])('counts any symbol, punctuation, or space as special: %s', (password) => {
|
||||
const result = check_password_strength(password);
|
||||
expect(result.report.hasSpecialChar.pass).toBe(true);
|
||||
expect(result.overallPass).toBe(true);
|
||||
});
|
||||
|
||||
it('does not count letters or digits as special', () => {
|
||||
const result = check_password_strength('Abcdéfg12');
|
||||
expect(result.report.hasSpecialChar.pass).toBe(false);
|
||||
expect(result.overallPass).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['Abc1!', 'minLength'],
|
||||
['abcdefg1!', 'hasUpperCase'],
|
||||
['ABCDEFG1!', 'hasLowerCase'],
|
||||
['Abcdefgh!', 'hasNumber'],
|
||||
])('fails %s on %s', (password, criterion) => {
|
||||
const result = check_password_strength(password);
|
||||
expect(result.report[criterion].pass).toBe(false);
|
||||
expect(result.overallPass).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user