passkey-creator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +60 -0
  2. package/index.js +108 -0
  3. package/package.json +27 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+
2
+ # Password Creator CLI
3
+
4
+ This is a simple CLI tool that generates a random password based on user inputs,
5
+ such as the desired length and the inclusion of lowercase letters, uppercase letters, numbers, and symbols.
6
+ It uses `inquirer`, `chalk`, and `gradient-string` to provide a rich user interface and a customizable password.
7
+
8
+ ## Table of Contents
9
+ 1. [Installation](#installation)
10
+ 2. [Usage](#usage)
11
+ 3. [Tip](#Tip)
12
+ 3. [Features](#features)
13
+ 4. [Dependencies](#dependencies)
14
+ 5. [License](#license)
15
+
16
+ ## Installation
17
+
18
+ 1. Install the cli tool by running:
19
+ ```bash
20
+ npm install -g passkey-creator
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ To run the password generator, open the terminal and execute the following command:
26
+
27
+ ```bash
28
+ create-key
29
+ ```
30
+
31
+ You'll be prompted with a series of questions asking about the length of the password and which types of characters to include.
32
+
33
+
34
+ ## Tip
35
+
36
+ - I know that writing this big command is not affordable for your fingers. So to shorten this command follow these steps :-
37
+
38
+ 1. Open bash
39
+ 2. Type the command :
40
+
41
+ ```bash
42
+ alias key="create-key"
43
+ ```
44
+ This will save you some keystrokes. Note that this alias will only persist for the current terminal session. To make it permanent, add the alias to your .bashrc or .zshrc file.
45
+
46
+ ## Features
47
+
48
+ - **Customizable Password Length**: You can define the length of the generated password.
49
+ - **Character Type Options**: Choose whether to include lowercase letters, uppercase letters, numbers, and symbols.
50
+ - **Rich User Interface**: The CLI interface is styled using `chalk` and `gradient-string` for a smooth user experience.
51
+ - **Easy-to-Use**: The CLI prompts make it easy to interact with and customize the password generation.
52
+
53
+ ## Dependencies
54
+
55
+ - `inquirer`: For interactive CLI prompts.
56
+ - `chalk`: For colorful terminal output.
57
+
58
+ ## License
59
+
60
+ This project is licensed under the [ISC License](https://opensource.org/licenses/ISC).
package/index.js ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+
3
+ import inquirer from "inquirer";
4
+ import chalk from "chalk";
5
+
6
+ // Color definitions
7
+ const warningColor = chalk.hex("#FF6F20"); // Warning color
8
+ const successColor = chalk.hex("#B2E2D9"); // Success color
9
+ const neutralColor = chalk.hex("#E6F9E9"); // Neutral color
10
+ const promptColor = chalk.hex("#E0F7FA"); // Prompt color
11
+ const infoColor = chalk.hex("#B3D3E3"); // Info color
12
+ const dangerColor = chalk.hex("#DC143C"); // Danger color
13
+ const bg = chalk.bgHex("#E0F7FA").hex("#2C3E50"); // Background color
14
+
15
+
16
+ // Function to generate password
17
+ function generatePassword(
18
+ length,
19
+ includeLowercase,
20
+ includeUppercase,
21
+ includeNumbers,
22
+ includesymbols
23
+ ) {
24
+ const lowercase = "abcdefghijklmnopqrstuvwxyz";
25
+ const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
26
+ const number = "1234567890";
27
+ const symbols = "!@#$%^&*()_+";
28
+
29
+ let allowedchars = "";
30
+ let password = "";
31
+
32
+ allowedchars += includeLowercase ? lowercase : "";
33
+ allowedchars += includeUppercase ? uppercase : "";
34
+ allowedchars += includeNumbers ? number : "";
35
+ allowedchars += includesymbols ? symbols : "";
36
+
37
+ if (length < 1) {
38
+ return `(Length should not be less than 1)`;
39
+ }
40
+ if (allowedchars === "") {
41
+ return `(At least one character set must be selected)`;
42
+ } else {
43
+ for (let i = 0; i < length; i++) {
44
+ const random = Math.floor(Math.random() * allowedchars.length);
45
+ password += allowedchars[random];
46
+ }
47
+ }
48
+ return password;
49
+ }
50
+
51
+ // Main function to interact with the user and generate the password
52
+ (async () => {
53
+ console.log(bg(`\nWelcome to the Password Generator!`));
54
+ console.log(infoColor("\nLet's customize your password options.\n"));
55
+
56
+ const { len } = await inquirer.prompt({
57
+ name: "len",
58
+ message: `${promptColor("Enter password length:")}`,
59
+ type: "input",
60
+ validate: (inp) => {
61
+ if (inp.trim() === "") return warningColor("Length is required.");
62
+ if (isNaN(inp) || parseInt(inp) < 1) return dangerColor("Enter a valid number greater than 0.");
63
+ return true;
64
+ }
65
+ });
66
+
67
+ const { lowcase } = await inquirer.prompt({
68
+ name: "lowcase",
69
+ message: `${promptColor("Include lowercase letters?")}`,
70
+ type: "list",
71
+ choices: ["Yes", "No"],
72
+ });
73
+
74
+ const { upcase } = await inquirer.prompt({
75
+ name: "upcase",
76
+ message: `${promptColor("Include uppercase letters?")}`,
77
+ type: "list",
78
+ choices: ["Yes", "No"],
79
+ });
80
+
81
+ const { symbols } = await inquirer.prompt({
82
+ name: "symbols",
83
+ message: `${promptColor("Include symbols?")}`,
84
+ type: "list",
85
+ choices: ["Yes", "No"],
86
+ });
87
+
88
+ const { numbers } = await inquirer.prompt({
89
+ name: "numbers",
90
+ message: `${promptColor("Include numbers?")}`,
91
+ type: "list",
92
+ choices: ["Yes", "No"],
93
+ });
94
+
95
+ const change = (val) => val === "Yes";
96
+
97
+ // Generate password based on user input
98
+ const password = generatePassword(
99
+ parseInt(len),
100
+ change(lowcase),
101
+ change(upcase),
102
+ change(numbers),
103
+ change(symbols)
104
+ );
105
+
106
+ console.log(successColor(`\nGenerated Password: `), neutralColor(password));
107
+
108
+ })();
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "passkey-creator",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "private":false,
7
+ "scripts": {
8
+ "start": "node ."
9
+ },
10
+ "bin": {
11
+ "create-key":"index.js"
12
+ },
13
+ "keywords": [
14
+ "password",
15
+ "security",
16
+ "cli",
17
+ "password-generator"
18
+ ],
19
+ "author": "Massachusetts",
20
+ "license": "ISC",
21
+ "description": "A CLI tool to generate strong and customizable passwords!",
22
+
23
+ "dependencies": {
24
+ "chalk": "^5.3.0",
25
+ "inquirer": "^11.0.2"
26
+ }
27
+ }