
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
credentials-validator
Advanced tools
npm install credentials-validator
const validator = require("credentials-validator");
user = {
name: "AnnieCare1010",
email: "annie@email.com",
password: "Password10"
};
validator.validate(user, function(errors) {
console.table(errors);
});
You will notice that will produce no errors. But what happens if we change the password to "Pass", which has only 4 characters?
password: "Pass"
It will produce...
┌─────────┬────────────────────────────────────────────────────┐
│ (index) │ Values │
├─────────┼────────────────────────────────────────────────────┤
│ 0 │ 'Password too short, max length: 8' │
└─────────┴────────────────────────────────────────────────────┘
Voila! it produced an error.
Here is the available settings:
var settings = {
nameMin: 5,
nameMax: 15,
passwordMin: 8,
passwordMax: 20,
passwordMustContainUpper: false,
passwordMustContainNumber: false,
passwordSpecialCharactersPermit: false
};
And you can change the settings using the setSettings() method
const validator = require("credentials-validator");
const newSettings = {
nameMin: 10,
nameMax: 25,
passwordMustContainUpper: false
};
validator.setSettings(newSettings);
You can set custom error messages.
user = {
name: "AnnieCare1010",
email: "annie@email.com",
password: "Password10"
};
const errorMessages = {
errorPasswordMin: "Senha curta, tamanho máximo: __VALUE__"
//__VALUE__ gets replaced by the current value, which is password min length in this case
};
validator.validate(user, function(errors) {
console.table(errors);
});
validator.setErrorMessages(errorMessages);
It will print...
┌─────────┬──────────────────────────────────┐
│ (index) │ Values │
├─────────┼──────────────────────────────────┤
│ 0 │ 'Senha curta, tamanho máximo: 8' │
└─────────┴──────────────────────────────────┘
//A method that individually checks a name
validator.checkName("JohnDoe" ,function(errs) {
console.log(errs);
});
//A method that individually checks an email
validator.checkEmail("john@gmail.com",function(errs) {
console.log(errs);
});
//A method that individually checks an email
validator.checkEmail("Password10",function(errs) {
console.log(errs);
});
Example:
const customCredential = "AyeMate"
settings = {
min: 10,
max: 20
};
/*
Check out the full settings in next code sample
*/
errorMessages = {
errorMin: "__NAME__ is low! Min length: __VALUE__"
};
/*
__NAME__ gets replaced by the credential name,
check out the full error message in the next code sample
*/
//checkCustom(credential, name, callback, customSettings, customErrorMessages);
validator.checkCustom(
customCredential,
"Custom credential",
function(errs) {
errors.push(errs);
},
settings,
errorMessages
);
Full custom settings and error messages
let cSettings = {
min: 0,
max: 0,
mustContainWord: [],
mustContainUpper: false,
mustContainNumber: false,
specialCharactersPermit: true
};
let cErrorMessages = {
errorEmpty: "Empty __NAME__!",
errorMin: "__NAME__ too short, min length: __VALUE__",
errorMax: "__NAME__ too long, max length: __VALUE__",
errorWord: "__NAME__ should contain this word: __VALUE__",
errorUpper: "__NAME__ should contain at last 1 uppercase!",
errorNumber: "__NAME__ should contain at last 1 number!",
errorSpecialFalse: "Forbidden characters in __NAME__",
errorSpecialTrue: "__NAME__ should contain at last 1 special characters!"
};
FAQs
A simple credential validator
We found that credentials-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.