This answer from @Huhngut provides a succinct way to test the strength of passwords using the express-validator
method isStrongPassword()
. For example:
body('password').isStrongPassword({
minLength: 12,
minLowercase: 1,
minUppercase: 1,
minNumbers: 1,
minSymbols: 1,
})
However this code above allows me to enter anything into the password field which makes me concerned that could pose a security risk. I would like to ask:
- Which non-alphanumeric characters should be allowed?
- Is there a preferred
express-validator
method for implementing allowable characters e.g..matches()
/.whitelist()
etc. - Is there a recommended maximum length for passwords, and how should that be implemented since
.isStrongPassword()
doesn't have a maximum length option?
More generally I am trying to find the best practice for implementing logic within express-validator
and node.js
that minimizes the risk to my server while enforcing strong passwords.