New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

check-password-strength

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-password-strength - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

39

index.js
export function passwordStrength(password) {
const strongRegex = new RegExp(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})"
);
const mediumRegex = new RegExp(
"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"
);
if (strongRegex(password)) {
return "Strong";
} else if (mediumRegex(password)) {
return "Medium";
} else {
return "Weak";
}
}
let strength = { // Default
id: 0,
value: 'Weak'
}
const strongRegex = new RegExp(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})"
);
const mediumRegex = new RegExp(
"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"
);
if (strongRegex.test(password)) {
strength.id = 2
return strength;
} else if (mediumRegex.test(password)) {
strength.id = 1
strength.value = 'Medium'
} else {
strength.id = 0
strength.value = 'Weak'
}
return strength;
}
{
"name": "check-password-strength",
"version": "1.0.1",
"version": "1.0.2",
"description": "Password strength checker based from Javascript RegExp",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,2 +1,4 @@

# Overview
A simple way to check that password strength of a certain passphrase. A password strength checker based from [Javascript RegEx](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).

@@ -6,24 +8,39 @@

npm i check-password-strength
`npm i check-password-strength --save`
## Setup & Basic Usage
```
const { passwordStrength } = require('check-password-strength')
console.log(passwordStrength(asdfasdf))
console.log(passwordStrength('asdfasdf').value)
// Weak (It wiill return weak if the value doesn't match the RegEx conditions)
console.log(passwordStrength(asdfasdf2020))
console.log(passwordStrength('Asdfasdf2020').value)
// Medium
console.log(passwordStrength(A@2asdF2020!!*))
console.log(passwordStrength('A@2asdF2020!!*').value)
// Strong
```
## Additional Info
**Strong Password RegEx used:** `^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})`
### Object
| Property| Desc. |
| -- | -- |
| id | **0** = Weak, **1** = Medium & **2** = Strong |
| value | Weak, Medium & Strong |
**Medium Password RegEx used:** `^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"`
```
console.log(passwordStrength('Asdfasdf2020'))
// { id: 1, value: 'Weak' }
```
### RegEx
**Strong Password RegEx used:**
`^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})`
**Medium Password RegEx used:**
`^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"`
|RegEx| Desc. |

@@ -38,3 +55,2 @@ |--|--|

Credits to Nic Raboy for his awesome [blog!](https://www.thepolyglotdeveloper.com/2015/05/use-regex-to-test-password-strength-in-javascript/)

@@ -45,3 +61,2 @@

### License
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/deanilvincent/check-password-strength/blob/master/LICENSE.md/) file for details.
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/deanilvincent/check-password-strength/blob/master/LICENSE.md/) file for details.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc