26 lines
595 B
TypeScript
26 lines
595 B
TypeScript
export type PasswordChecks = {
|
|
lengthOk: boolean;
|
|
lowerOk: boolean;
|
|
upperOk: boolean;
|
|
digitOk: boolean;
|
|
specialOk: boolean;
|
|
allOk: boolean;
|
|
};
|
|
|
|
export function evaluatePassword(password: string): PasswordChecks {
|
|
const lengthOk = password.length >= 12;
|
|
const lowerOk = /[a-z]/.test(password);
|
|
const upperOk = /[A-Z]/.test(password);
|
|
const digitOk = /\d/.test(password);
|
|
const specialOk = /[^A-Za-z0-9]/.test(password);
|
|
|
|
return {
|
|
lengthOk,
|
|
lowerOk,
|
|
upperOk,
|
|
digitOk,
|
|
specialOk,
|
|
allOk: lengthOk && lowerOk && upperOk && digitOk && specialOk,
|
|
};
|
|
}
|