check-password-strength
Advanced tools
Comparing version
77
index.js
module.exports = (password) => { | ||
if (!password) { | ||
console.error("check-password-strength package - requires a password value.") | ||
return undefined | ||
throw new Error("Password is empty."); | ||
} | ||
let strength = {} // Default | ||
const lowerCaseRegex = "(?=.*[a-z])"; | ||
const upperCaseRegex = "(?=.*[A-Z])"; | ||
const symbolsRegex = "(?=.*[!@#$%^&*])"; | ||
const numericRegex = "(?=.*[0-9])"; | ||
let strength = { | ||
id: null, | ||
value: null, | ||
length: null, | ||
contains: [], | ||
}; | ||
// Default | ||
let passwordContains = []; | ||
if (new RegExp(`^${lowerCaseRegex}`).test(password)) { | ||
passwordContains = [ | ||
...passwordContains, | ||
{ | ||
message: "lowercase", | ||
}, | ||
]; | ||
} | ||
if (new RegExp(`^${upperCaseRegex}`).test(password)) { | ||
passwordContains = [ | ||
...passwordContains, | ||
{ | ||
message: "uppercase", | ||
}, | ||
]; | ||
} | ||
if (new RegExp(`^${symbolsRegex}`).test(password)) { | ||
passwordContains = [ | ||
...passwordContains, | ||
{ | ||
message: "symbol", | ||
}, | ||
]; | ||
} | ||
if (new RegExp(`^${numericRegex}`).test(password)) { | ||
passwordContains = [ | ||
...passwordContains, | ||
{ | ||
message: "number", | ||
}, | ||
]; | ||
} | ||
const strongRegex = new RegExp( | ||
"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})" | ||
`^${lowerCaseRegex}${upperCaseRegex}${numericRegex}${symbolsRegex}(?=.{8,})` | ||
); | ||
const mediumRegex = new RegExp( | ||
"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})" | ||
`^((${lowerCaseRegex}${upperCaseRegex})|(${lowerCaseRegex}${numericRegex})|(${upperCaseRegex}${numericRegex}))(?=.{6,})` | ||
); | ||
@@ -19,17 +67,18 @@ | ||
id: 2, | ||
value: 'Strong' | ||
} | ||
value: "Strong", | ||
}; | ||
} else if (mediumRegex.test(password)) { | ||
strength = { | ||
id: 1, | ||
value: 'Medium' | ||
} | ||
value: "Medium", | ||
}; | ||
} else { | ||
strength = { | ||
id: 0, | ||
value: 'Weak' | ||
} | ||
value: "Weak", | ||
}; | ||
} | ||
return strength | ||
} | ||
strength.length = password.length; | ||
strength.contains = passwordContains; | ||
return strength; | ||
}; |
{ | ||
"name": "check-password-strength", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "A NPM Password strength checker based from Javascript RegExp. Check passphrase if it's \"Weak\", \"Medium\" or \"Strong\"", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "jest" | ||
}, | ||
@@ -23,3 +23,9 @@ "repository": { | ||
"password checker strength", | ||
"strength password checker" | ||
"strength password checker", | ||
"check-password-strength", | ||
"password-strength-checker", | ||
"strength-checker", | ||
"password-checker", | ||
"password-checker-strength", | ||
"strength-password-checker" | ||
], | ||
@@ -32,6 +38,5 @@ "author": "deanilvincent", | ||
"homepage": "https://github.com/deanilvincent/check-password-strength#readme", | ||
"dependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^7.1.0" | ||
"devDependencies": { | ||
"jest": "^26.4.2" | ||
} | ||
} |
@@ -34,7 +34,15 @@ | ||
| value | Weak, Medium & Strong | | ||
| contains | lowercase, uppercase, symbol and/or number | | ||
| length | length of the password | | ||
``` | ||
console.log(passwordStrength('Asdfasdf2020')) | ||
// { id: 1, "value": "Medium" } | ||
console.log(passwordStrength('@Sdfasd2020!@#$')) | ||
// output | ||
{ | ||
"id": 1, | ||
"value": "Strong", | ||
"contains": [{'message': 'lowercase'},{'message': 'uppercase'},{'message': 'symbol'},{'message': 'number'}], | ||
"length": 15 | ||
} | ||
``` | ||
@@ -41,0 +49,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10045
52.15%0
-100%159
156.45%81
10.96%1
Infinity%1
Infinity%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed