-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (98 loc) · 3 KB
/
index.js
File metadata and controls
116 lines (98 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
import {intro, outro, spinner, text, confirm, isCancel, cancel, log} from '@clack/prompts';
import generator from 'generate-password';
import { setTimeout } from 'node:timers/promises';
import figlet from 'figlet';
import color from 'picocolors';
async function main(){
intro(`${color.bgCyan('Welcome to PasswordCLI.')}`);
const length = await text({
message: 'Enter the length of password: ',
validate(value){
if(!value) { return `Please enter a value!`};
if(parseInt(value) < 5){
return `Length too short! Must be greater than 4. Please enter again...`;
}
}
});
if (isCancel(length)) {
cancel('Operation cancelled.');
process.exit(0);
}
const numbers = await confirm({
message: 'Do you want to include numbers?'
})
if (isCancel(numbers)) {
cancel('Operation cancelled.');
process.exit(0);
}
const symbols = await confirm({
message: 'Do you want to include symbols?'
})
if (isCancel(symbols)) {
cancel('Operation cancelled.');
process.exit(0);
}
const multiple = await confirm({
message: 'Do you want to generate multiple passwords?'
})
let password;
if(multiple){
const count = await text({
message: 'Enter the number of passwords to be generated: ',
validate(value){
if(!value) { return `Please enter a value!`};
if(parseInt(value) < 2){
return `Value must be greater than 1.`;
}
}
})
password = generator.generateMultiple(count, {
length: length,
symbols: symbols,
numbers: numbers
})
const s = spinner();
s.start('Generating...');
await setTimeout(2000);
s.stop();
console.log(color.bold("Passwords: "));
} else{
password = generator.generate({
length: length,
symbols: symbols,
numbers: numbers
})
const s = spinner();
s.start('Generating...');
await setTimeout(1000);
s.stop();
console.log(color.bold("Password: "));
}
if(password == ''){
log.error(color.red(`Error generating password! Please check the values entered and try again.`));
} else{
if(multiple){
let multiPasswords = [];
multiPasswords = password.join(', ');
log.success(color.green(multiPasswords));
}else{
log.success(color.green(password));
}
outro(`${color.bgCyan('Thank You!')}`);
}
figlet.text(
"PasswordCLI",
{
font: "Standard",
},
function (err, data) {
if (err) {
console.log("Something went wrong...");
console.dir(err);
return;
}
console.log(data);
});
}
main().catch(console.error);