Implement password validation and update user model roles

This commit is contained in:
Isuru Bimsara
2026-08-15 00:24:36 +05:30
parent 81d0e65686
commit ef8db0988b
3 changed files with 58 additions and 22 deletions
@@ -0,0 +1,31 @@
const validatePassword = (password) => {
// Check if password is a string
if (typeof password !== "string") {
return false;
}
// At least 1 uppercase letter
const hasUppercase = /[A-Z]/.test(password);
// At least 1 lowercase letter
const hasLowercase = /[a-z]/.test(password);
// At least 1 symbol
const hasSymbol = /[^A-Za-z0-9]/.test(password);
// At least 4 numbers
const numberCount = (password.match(/[0-9]/g) || []).length;
const hasFourNumbers = numberCount >= 4;
return (
hasUppercase &&
hasLowercase &&
hasSymbol &&
hasFourNumbers
);
};
module.exports = {
validatePassword,
};