show-password-strength 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/index.js +61 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# About
|
|
2
|
+
|
|
3
|
+
A simple and efficient npm package to validate password strength using rules such as minimum length, numbers, lowercase letters, uppercase letters, and special characters.
|
|
4
|
+
|
|
5
|
+
# Features
|
|
6
|
+
|
|
7
|
+
* Validates password minimum length
|
|
8
|
+
* Checks for numeric characters
|
|
9
|
+
* Ensures lowercase letters are included
|
|
10
|
+
* Ensures uppercase letters are included
|
|
11
|
+
* Validates presence of special characters
|
|
12
|
+
* Simple and easy-to-use API
|
|
13
|
+
* Lightweight with zero external dependencies
|
|
14
|
+
* Works in both frontend and backend JavaScript applications
|
|
15
|
+
* Easy to integrate with any authentication or form validation flow
|
|
16
|
+
|
|
17
|
+
# Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install show-password-strength
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
# Usage
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import showPasswordStrength from 'show-password-strength'
|
|
27
|
+
|
|
28
|
+
const passwordStrengthOne = showPasswordStrength("midh", 6)
|
|
29
|
+
console.log(passwordStrengthOne) // {level: "weak", score: 25}
|
|
30
|
+
|
|
31
|
+
const passwordStrengthTwo = showPasswordStrength("midhun", 6)
|
|
32
|
+
console.log(passwordStrengthTwo) // {level: "medium", score: 33}
|
|
33
|
+
|
|
34
|
+
const passwordStrengthThree = showPasswordStrength("midhun123U", 6)
|
|
35
|
+
console.log(passwordStrengthThree) // {level: "strong", score: 50}
|
|
36
|
+
|
|
37
|
+
const passwordStrengthFour = showPasswordStrength("midhun123@U", 6)
|
|
38
|
+
console.log(passwordStrengthFour) // {level: "strong", score: 75}
|
|
39
|
+
|
|
40
|
+
const passwordStrengthFive = showPasswordStrength("Midhun123@whoam", 6)
|
|
41
|
+
console.log(passwordStrengthFive) // {level: "strong", score: 100}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
# ISC License
|
|
45
|
+
|
|
46
|
+
Copyright (c) 2025 Midhun
|
|
47
|
+
|
|
48
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
49
|
+
|
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
51
|
+
|
|
52
|
+
Readme
|
package/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@param {string} password - The password which is for checking if the password is strong
|
|
3
|
+
@param {number} minLength - The minimum length of the password should be
|
|
4
|
+
@returns {{level: "weak" | "medium" | "strong", score: number}}
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Function for checking password is strong
|
|
8
|
+
const showPasswordStrength = (password, minLength) => {
|
|
9
|
+
|
|
10
|
+
const hasLower = /[a-z]/.test(password) // For checking if password contains lower characters
|
|
11
|
+
const hasUpper = /[A-Z]/.test(password) // For checking if password contains upper characters
|
|
12
|
+
const hasNumber = /[0-9]/.test(password) // For checking if password contains numbers
|
|
13
|
+
const hasSpecialCharacters = /[^A-Za-z0-9]/.test(password) // For checking if password contains special characters
|
|
14
|
+
|
|
15
|
+
if (password.length < minLength) {
|
|
16
|
+
return { level: "weak", score: 100 / 4 }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if(
|
|
20
|
+
(password.length >= minLength + minLength) &&
|
|
21
|
+
hasLower &&
|
|
22
|
+
hasNumber &&
|
|
23
|
+
hasUpper &&
|
|
24
|
+
hasSpecialCharacters
|
|
25
|
+
){
|
|
26
|
+
return {level: "strong", score: 100}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(
|
|
30
|
+
password.length >= minLength &&
|
|
31
|
+
hasLower &&
|
|
32
|
+
hasNumber &&
|
|
33
|
+
hasUpper &&
|
|
34
|
+
hasSpecialCharacters
|
|
35
|
+
){
|
|
36
|
+
return {level: "strong", score: 75}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
password.length >= minLength &&
|
|
41
|
+
hasLower &&
|
|
42
|
+
hasUpper &&
|
|
43
|
+
hasNumber
|
|
44
|
+
) {
|
|
45
|
+
return { level: "strong", score: 50 }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
(password.length >= minLength) &&
|
|
50
|
+
hasLower ||
|
|
51
|
+
hasUpper ||
|
|
52
|
+
hasNumber ||
|
|
53
|
+
hasSpecialCharacters
|
|
54
|
+
) {
|
|
55
|
+
|
|
56
|
+
return { level: "medium", score: Math.round(100 / 3) }
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default showPasswordStrength
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "show-password-strength",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A small NPM package for checking password strength.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "node ./index.js",
|
|
9
|
+
"dev": "node --watch ./index.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Midhun-u/show-password-strength.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"password",
|
|
17
|
+
"password",
|
|
18
|
+
"strength",
|
|
19
|
+
"check",
|
|
20
|
+
"password",
|
|
21
|
+
"strength",
|
|
22
|
+
"npm",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"password",
|
|
25
|
+
"checker"
|
|
26
|
+
],
|
|
27
|
+
"author": "midhun-u",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/Midhun-u/show-password-strength/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Midhun-u/show-password-strength#readme"
|
|
33
|
+
}
|