const { validationEmail } = require('../utils/validationEmail') var verifyPasswordStrength = async function verify(req, res, next) { try { var query = req.body; if (query.hasOwnProperty('email') && query.hasOwnProperty('password') && query.hasOwnProperty('confirm_password')) { if (validationEmail(query.email)) { if (query['password'] == query['confirm_password']) { var matchedCase = []; matchedCase.push("[$@$!%*#?&]"); // Special Charector matchedCase.push("[A-Z]"); // Uppercase Alpabates matchedCase.push("[0-9]"); // Numbers matchedCase.push("[a-z]"); // Lowercase Alphabates // Check the conditions var ctr = 0; for (var i = 0; i < matchedCase.length; i++) { if (new RegExp(matchedCase[i]).test(query.password)) { ctr++; } } // controll validation. if (ctr == 4 && query.password.length >= 8) { next(); } else { return res.status(401).send({ code: 401, error: 'Password Strength Validation' }); } } else { return res.status(401).send({ code: 401, error: 'Password is not match with confirm passowrd' }) } } else { return res.status(401).send({ code: 401, error: 'Please specific your email' }) } } else { return res.status(401).send({ code: 401, error: 'Please specific your email, password and confirm password' }); } } catch (error) { return res.status(500).send({ code: 401, error: 'Internal Server Error' }); } } module.exports = { verifyPasswordStrength }