Implement password validation and update user model roles
This commit is contained in:
@@ -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,
|
||||
};
|
||||
Reference in New Issue
Block a user