password-gen-lite 0.0.0-stage → 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/LICENSE +8 -0
- package/README.md +149 -2
- package/bin/cli.js +102 -0
- package/package.json +26 -4
- package/src/chars.js +13 -0
- package/src/index.js +66 -0
package/LICENSE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,150 @@
|
|
|
1
|
-
#
|
|
1
|
+
# password-gen-lite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, cryptographically secure password generator for Node.js with zero external dependencies.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install globally to use as a CLI command anywhere:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g password-gen-lite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or run directly without installing using `npx`:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx password-gen-lite
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or add to your project:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install password-gen-lite
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## CLI Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Generate a default 12-character strong password
|
|
31
|
+
password-gen-lite
|
|
32
|
+
|
|
33
|
+
# Generate a 16-character password
|
|
34
|
+
password-gen-lite 16
|
|
35
|
+
|
|
36
|
+
# Exclude special characters
|
|
37
|
+
password-gen-lite 16 --no-symbols
|
|
38
|
+
|
|
39
|
+
# Exclude digits
|
|
40
|
+
password-gen-lite 16 --no-numbers
|
|
41
|
+
|
|
42
|
+
# Exclude uppercase letters
|
|
43
|
+
password-gen-lite 16 --no-uppercase
|
|
44
|
+
|
|
45
|
+
# Exclude lowercase letters
|
|
46
|
+
password-gen-lite 16 --no-lowercase
|
|
47
|
+
|
|
48
|
+
# Generate 5 passwords at once
|
|
49
|
+
password-gen-lite 16 -c 5
|
|
50
|
+
|
|
51
|
+
# View help and options
|
|
52
|
+
password-gen-lite --help
|
|
53
|
+
|
|
54
|
+
# View version number
|
|
55
|
+
password-gen-lite --version
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## CLI Options
|
|
61
|
+
|
|
62
|
+
| Flag | Description | Default |
|
|
63
|
+
| :--- | :--- | :--- |
|
|
64
|
+
| `[length]` | Length of generated password (between 4 and 128) | `12` |
|
|
65
|
+
| `-c, --count <num>` | Number of passwords to generate | `1` |
|
|
66
|
+
| `--no-symbols` | Disable special characters (`!@#$%^&*...`) | `false` |
|
|
67
|
+
| `--no-numbers` | Disable numbers (`0-9`) | `false` |
|
|
68
|
+
| `--no-uppercase` | Disable uppercase letters (`A-Z`) | `false` |
|
|
69
|
+
| `--no-lowercase` | Disable lowercase letters (`a-z`) | `false` |
|
|
70
|
+
| `-h, --help` | Show command instructions | |
|
|
71
|
+
| `-v, --version` | Display package version | |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Programmatic Usage
|
|
76
|
+
|
|
77
|
+
Import `generatePassword` into your Node.js application:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const { generatePassword } = require('password-gen-lite');
|
|
81
|
+
|
|
82
|
+
// Default 12-character password
|
|
83
|
+
const pass1 = generatePassword();
|
|
84
|
+
console.log(pass1);
|
|
85
|
+
|
|
86
|
+
// Custom length of 16 characters
|
|
87
|
+
const pass2 = generatePassword(16);
|
|
88
|
+
console.log(pass2);
|
|
89
|
+
|
|
90
|
+
// Custom length without symbols
|
|
91
|
+
const pass3 = generatePassword(20, { symbols: false });
|
|
92
|
+
console.log(pass3);
|
|
93
|
+
|
|
94
|
+
// Using an options object
|
|
95
|
+
const pass4 = generatePassword({
|
|
96
|
+
length: 24,
|
|
97
|
+
symbols: true,
|
|
98
|
+
numbers: true,
|
|
99
|
+
uppercase: true,
|
|
100
|
+
lowercase: true
|
|
101
|
+
});
|
|
102
|
+
console.log(pass4);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Options Reference
|
|
106
|
+
|
|
107
|
+
| Option | Type | Default | Description |
|
|
108
|
+
| :--- | :--- | :--- | :--- |
|
|
109
|
+
| `lowercase` | `boolean` | `true` | Include lowercase letters (`a-z`) |
|
|
110
|
+
| `uppercase` | `boolean` | `true` | Include uppercase letters (`A-Z`) |
|
|
111
|
+
| `numbers` | `boolean` | `true` | Include digits (`0-9`) |
|
|
112
|
+
| `symbols` | `boolean` | `true` | Include punctuation and symbols |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Sample Output
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
$ password-gen-lite 16
|
|
120
|
+
k9#mP2$vR8!xL5@w
|
|
121
|
+
|
|
122
|
+
$ password-gen-lite 16 --no-symbols
|
|
123
|
+
j8N4qL9wK2vR7mX1
|
|
124
|
+
|
|
125
|
+
$ password-gen-lite 12 -c 3
|
|
126
|
+
9m#P!2xK@5wL
|
|
127
|
+
k8$vR7^mQ1*a
|
|
128
|
+
3x@L9!vP4#mK
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## How It Works
|
|
134
|
+
|
|
135
|
+
1. **Cryptographic Randomness (`crypto.randomInt`)**: Standard pseudo-random engines like `Math.random()` are predictable and not suited for security credentials. This package uses Node's built-in `crypto.randomInt()`, which pulls entropy directly from the operating system's CSPRNG (Cryptographically Secure Pseudo-Random Number Generator).
|
|
136
|
+
2. **Guaranteed Strength**: At least one character is picked from every enabled category (lowercase, uppercase, digit, symbol) so passwords never accidentally lack complexity.
|
|
137
|
+
3. **Fisher-Yates Shuffle**: To ensure guaranteed characters do not stay stuck at predictable starting indices, the complete character array is shuffled using an unbiased Fisher-Yates algorithm powered by `crypto.randomInt()`.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Author
|
|
142
|
+
|
|
143
|
+
**Prashant**
|
|
144
|
+
Email: prashantofficial627@gmail.com
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT (c) 2026 Prashant
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { generatePassword } = require('../src/index');
|
|
5
|
+
const packageJson = require('../package.json');
|
|
6
|
+
|
|
7
|
+
function printHelp() {
|
|
8
|
+
console.log(`password-gen-lite v${packageJson.version}
|
|
9
|
+
A simple and secure password generator.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
password-gen-lite [length] [options]
|
|
13
|
+
npx password-gen-lite [length] [options]
|
|
14
|
+
|
|
15
|
+
Arguments:
|
|
16
|
+
length Password length (4-128, default: 12)
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
-c, --count <num> Number of passwords to generate (default: 1)
|
|
20
|
+
--no-lowercase Exclude lowercase letters (a-z)
|
|
21
|
+
--no-uppercase Exclude uppercase letters (A-Z)
|
|
22
|
+
--no-numbers Exclude numbers (0-9)
|
|
23
|
+
--no-symbols Exclude symbols (!@#$%^&*...)
|
|
24
|
+
-h, --help Show help
|
|
25
|
+
-v, --version Show version
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
password-gen-lite
|
|
29
|
+
password-gen-lite 16
|
|
30
|
+
password-gen-lite 20 --no-symbols
|
|
31
|
+
password-gen-lite 16 -c 5
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseArgs(args) {
|
|
36
|
+
const options = {
|
|
37
|
+
length: 12,
|
|
38
|
+
count: 1,
|
|
39
|
+
lowercase: true,
|
|
40
|
+
uppercase: true,
|
|
41
|
+
numbers: true,
|
|
42
|
+
symbols: true
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < args.length; i++) {
|
|
46
|
+
const arg = args[i];
|
|
47
|
+
|
|
48
|
+
if (arg === '-h' || arg === '--help') {
|
|
49
|
+
printHelp();
|
|
50
|
+
process.exit(0);
|
|
51
|
+
} else if (arg === '-v' || arg === '--version') {
|
|
52
|
+
console.log(packageJson.version);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
} else if (arg === '--no-symbols') {
|
|
55
|
+
options.symbols = false;
|
|
56
|
+
} else if (arg === '--no-numbers') {
|
|
57
|
+
options.numbers = false;
|
|
58
|
+
} else if (arg === '--no-uppercase') {
|
|
59
|
+
options.uppercase = false;
|
|
60
|
+
} else if (arg === '--no-lowercase') {
|
|
61
|
+
options.lowercase = false;
|
|
62
|
+
} else if (arg === '-c' || arg === '--count') {
|
|
63
|
+
const count = parseInt(args[++i], 10);
|
|
64
|
+
if (isNaN(count) || count < 1) {
|
|
65
|
+
throw new Error('Count must be a positive number.');
|
|
66
|
+
}
|
|
67
|
+
options.count = count;
|
|
68
|
+
} else if (!arg.startsWith('-')) {
|
|
69
|
+
const length = parseInt(arg, 10);
|
|
70
|
+
if (isNaN(length)) {
|
|
71
|
+
throw new Error(`Invalid length: "${arg}". Length must be a number.`);
|
|
72
|
+
}
|
|
73
|
+
options.length = length;
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error(`Unknown option: "${arg}". Use --help for usage.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return options;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function main() {
|
|
83
|
+
try {
|
|
84
|
+
const args = process.argv.slice(2);
|
|
85
|
+
const options = parseArgs(args);
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < options.count; i++) {
|
|
88
|
+
const password = generatePassword(options.length, {
|
|
89
|
+
lowercase: options.lowercase,
|
|
90
|
+
uppercase: options.uppercase,
|
|
91
|
+
numbers: options.numbers,
|
|
92
|
+
symbols: options.symbols
|
|
93
|
+
});
|
|
94
|
+
console.log(password);
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.error(`Error: ${err.message}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "password-gen-lite",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight, secure password generator with zero external dependencies.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"password-gen-lite": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node --test"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"password",
|
|
14
|
+
"generator",
|
|
15
|
+
"random",
|
|
16
|
+
"secure",
|
|
17
|
+
"cli"
|
|
18
|
+
],
|
|
19
|
+
"author": "Prashant <prashantofficial627@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"src"
|
|
27
|
+
]
|
|
28
|
+
}
|
package/src/chars.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
|
|
4
|
+
const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
5
|
+
const NUMBERS = '0123456789';
|
|
6
|
+
const SYMBOLS = '!@#$%^&*()_+-=[]{}|;:,.<>?';
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
LOWERCASE,
|
|
10
|
+
UPPERCASE,
|
|
11
|
+
NUMBERS,
|
|
12
|
+
SYMBOLS
|
|
13
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const { LOWERCASE, UPPERCASE, NUMBERS, SYMBOLS } = require('./chars');
|
|
5
|
+
|
|
6
|
+
// Use crypto.randomInt instead of Math.random because it is cryptographically secure
|
|
7
|
+
function getRandomChar(str) {
|
|
8
|
+
const index = crypto.randomInt(0, str.length);
|
|
9
|
+
return str[index];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Fisher-Yates shuffle to mix characters randomly
|
|
13
|
+
function shuffle(array) {
|
|
14
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
15
|
+
const j = crypto.randomInt(0, i + 1);
|
|
16
|
+
const temp = array[i];
|
|
17
|
+
array[i] = array[j];
|
|
18
|
+
array[j] = temp;
|
|
19
|
+
}
|
|
20
|
+
return array;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function generatePassword(length = 12, options = {}) {
|
|
24
|
+
if (typeof length === 'object' && length !== null) {
|
|
25
|
+
options = length;
|
|
26
|
+
length = options.length || 12;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!Number.isInteger(length) || length < 4 || length > 128) {
|
|
30
|
+
throw new Error('Password length must be a whole number between 4 and 128.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const sets = [];
|
|
34
|
+
if (options.lowercase !== false) sets.push(LOWERCASE);
|
|
35
|
+
if (options.uppercase !== false) sets.push(UPPERCASE);
|
|
36
|
+
if (options.numbers !== false) sets.push(NUMBERS);
|
|
37
|
+
if (options.symbols !== false) sets.push(SYMBOLS);
|
|
38
|
+
|
|
39
|
+
if (sets.length === 0) {
|
|
40
|
+
throw new Error('At least one character set must be enabled.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (length < sets.length) {
|
|
44
|
+
throw new Error(`Password length must be at least ${sets.length} to include all selected character types.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result = [];
|
|
48
|
+
|
|
49
|
+
// Guarantee at least one character from each selected set
|
|
50
|
+
for (let i = 0; i < sets.length; i++) {
|
|
51
|
+
result.push(getRandomChar(sets[i]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const pool = sets.join('');
|
|
55
|
+
const remaining = length - result.length;
|
|
56
|
+
for (let i = 0; i < remaining; i++) {
|
|
57
|
+
result.push(getRandomChar(pool));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
shuffle(result);
|
|
61
|
+
|
|
62
|
+
return result.join('');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = generatePassword;
|
|
66
|
+
module.exports.generatePassword = generatePassword;
|