Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express-validator isStrongPassword() function is not working

I'm trying to do validation test by using express-validator.

so far everything is working good except isStrongPassword()

import {check} from "express-validator"


const val =   
    check('pwd')
        .exists()
        .withMessage('please enter the password')
        .isStrongPassword({minLength: 6})
        .withMessage('password is must be above six letters')

Router.post('/signup',val,SignUp)


const SignUp = async(req,res) => {
    // if email and password are invalid  throw the errors
    const errors = validationResult(req).array();
    if (errors && errors.length) {
    console.log(errors);
    res.status(400).json({ errors });

my code is like that .but when I request password 1 letter or 7 letters regardless It just call error. It seems to be doesn`t work anybody who knows why it happened? Thank you for your attention

like image 914
JungKi Kim Avatar asked Sep 15 '26 13:09

JungKi Kim


1 Answers

isStrongPassword has default values

enter image description here

Either you override the other properties with 0 or just follow the default values.

IMHO, a strong password should respect the combination of lower case, upper case, number, and special character, not only the minimal length.

I hope this answers your problem.

like image 73
taipei Avatar answered Sep 18 '26 10:09

taipei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!