pasaword 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 ADDED
File without changes
package/dist/index.js ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+ import fs from 'fs';
4
+ import clipboard from 'clipboardy'; // Добавили библиотеку для буфера
5
+ import { generatePassword } from './logic.js';
6
+ const DB_PATH = './vault.json';
7
+ const readDB = () => JSON.parse(fs.readFileSync(DB_PATH, 'utf-8'));
8
+ const writeDB = (data) => fs.writeFileSync(DB_PATH, JSON.stringify(data, null, 2));
9
+ const clr1 = chalk.rgb(201, 204, 161);
10
+ const clr2 = chalk.rgb(202, 160, 90);
11
+ const clr3 = chalk.rgb(174, 106, 71);
12
+ const clr4 = chalk.rgb(139, 64, 73);
13
+ const clr5 = chalk.rgb(84, 51, 68);
14
+ const clr6 = chalk.rgb(81, 82, 98);
15
+ const clr7 = chalk.rgb(99, 120, 125);
16
+ const clr8 = chalk.rgb(142, 160, 145);
17
+ function showLogo() {
18
+ console.clear();
19
+ // Определяем цвета заранее, чтобы код был читабельным
20
+ console.log(`
21
+ ${clr1(' _______')} ${clr1('<-P-A-S-A-W-O-R-D->')}
22
+ ${clr1(' / ___ \\')}
23
+ ${clr2(' / / \\ \\')} ${clr2('v1.1.0 (Custom Engine)')}
24
+ ${clr3(' _| |_____| |_')} ${clr3('Author: Dv4c')}
25
+ ${clr4(' [ __ ]')}
26
+ ${clr5(' | / \\ |')}
27
+ ${clr6(' | | | |')}
28
+ ${clr7(' | |||| |')}
29
+ ${clr8(' |_____________|')}
30
+ `);
31
+ }
32
+ const args = process.argv.slice(2);
33
+ const command = args[0];
34
+ async function main() {
35
+ showLogo();
36
+ if (!command || command === '-h' || command === '--help') {
37
+ console.log('\n ' + clr1('Options') + ':');
38
+ console.log(` ${clr2('-l, --list').padEnd(25)} ${clr7('Show list with all saved info')}`);
39
+ console.log(` ${clr2('-g, --generate').padEnd(25)} ${clr7('Generate password : ') + clr3('<service> <login>') + clr7(' [type] [len]')}`);
40
+ console.log(' ' + clr1('Default') + ': ' + clr7('type') + clr7(' : ') + clr3('A-z9#') + ', ' + clr7('length') + clr7(' : ') + clr3('8'));
41
+ console.log(' ' + clr1('Types') + ': ' + clr3('A-Z, A-z, a-z, A-9, a-9, 1-9, A-z9, A-z9#'));
42
+ console.log(` ${clr2('-s, --save').padEnd(25)} ${clr7('Save manual password: ') + clr3('<service> <login> <pass>')}`);
43
+ console.log(` ${clr2('-cp, --copy').padEnd(25)} ${clr7('Copy password to clipboard: ') + clr3('<id>')}`);
44
+ console.log(` ${clr2('-d, --delete').padEnd(25)} ${clr7('Delete record by number: ') + clr3('<id>')}`);
45
+ console.log();
46
+ process.exit(0);
47
+ }
48
+ switch (command) {
49
+ case '-l':
50
+ case '--list':
51
+ const db = readDB();
52
+ // Названия столбцов в первый цвет (clr1)
53
+ console.log(clr1('\n ID SERVICE LOGIN PASSWORD'));
54
+ // Линии во второй цвет (clr2)
55
+ console.log(clr2(' ——————————————————————————————————————————'));
56
+ db.forEach((item, i) => {
57
+ // Номера (ID) — clr1
58
+ const id = clr1(String(i + 1).padEnd(3));
59
+ // Сервисы — clr2
60
+ const svc = clr2(item.service.padEnd(12));
61
+ // Логины — clr1
62
+ const log = clr1(item.login.padEnd(14));
63
+ // Пароли — clr2
64
+ const pass = clr2(item.password);
65
+ console.log(` ${id} ${svc} ${log} ${pass}`);
66
+ });
67
+ console.log(clr2(' ——————————————————————————————————————————'));
68
+ // Tips в clr1
69
+ console.log(clr1('\n Tips:'));
70
+ // Команда в clr2, Описание в clr3
71
+ console.log(` ${clr2('-cp, --copy').padEnd(25)} ${clr7('Copy password to clipboard:')} ${clr3('<id>')}`);
72
+ break;
73
+ case '-g':
74
+ case '--generate':
75
+ const svcGen = args[1];
76
+ const logGen = args[2];
77
+ const typeGen = args[3] || 'A-z9#';
78
+ const lenGen = parseInt(args[4]) || 8;
79
+ if (!svcGen || !logGen) {
80
+ console.log(chalk.red('\n [!] Error: Service and login are required!'));
81
+ return;
82
+ }
83
+ const genPass = generatePassword(lenGen, typeGen);
84
+ const dbGen = readDB();
85
+ dbGen.push({ service: svcGen, login: logGen, password: genPass });
86
+ writeDB(dbGen);
87
+ clipboard.writeSync(genPass);
88
+ console.log(chalk.blue(` [+] Generated (${typeGen}, len: ${lenGen}): ${clr7(genPass)}`));
89
+ console.log(clr2(` [✔] Saved and copied to clipboard!`));
90
+ break;
91
+ case '-s':
92
+ case '--save':
93
+ const svcSet = args[1];
94
+ const logSet = args[2];
95
+ const passSet = args[3];
96
+ if (!svcSet || !logSet || !passSet) {
97
+ console.log(chalk.red('\n [!] Error: Missing data!'));
98
+ return;
99
+ }
100
+ const dbSet = readDB();
101
+ dbSet.push({ service: svcSet, login: logSet, password: passSet });
102
+ writeDB(dbSet);
103
+ console.log(clr2(`\n [✔] Manual entry for ${svcSet} saved successfully!`));
104
+ break;
105
+ case '-cp':
106
+ case '--copy':
107
+ const idCp = parseInt(args[1]);
108
+ const dbCp = readDB();
109
+ if (dbCp[idCp - 1]) {
110
+ clipboard.writeSync(dbCp[idCp - 1].password);
111
+ console.log(clr2(`\n [✔] Password for ${chalk.bold(dbCp[idCp - 1].service)} copied to clipboard!`));
112
+ }
113
+ else {
114
+ console.log(chalk.red('\n [!] Error: Record with this ID not found!'));
115
+ }
116
+ break;
117
+ case '-d':
118
+ case '--delete':
119
+ const id = parseInt(args[1]);
120
+ let list = readDB();
121
+ if (list[id - 1]) {
122
+ const removed = list.splice(id - 1, 1);
123
+ writeDB(list);
124
+ console.log(chalk.red(` [×] Deleted record for: ${removed[0].service}`));
125
+ }
126
+ else {
127
+ console.log(chalk.red(' [!] Error: Record with this ID not found!'));
128
+ }
129
+ break;
130
+ default:
131
+ console.log(chalk.red(`\n [!] Unknown command: ${command}`));
132
+ }
133
+ }
134
+ main();
package/dist/logic.js ADDED
@@ -0,0 +1,23 @@
1
+ // src/logic.ts
2
+ /**
3
+ * Генерирует случайный пароль заданной длины
4
+ */
5
+ export function generatePassword(length = 8, charsetType = 'A-z9#') {
6
+ const charsets = {
7
+ 'A-Z': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
8
+ 'a-z': 'abcdefghijklmnopqrstuvwxyz',
9
+ 'A-z': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
10
+ 'A-9': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
11
+ 'a-9': 'abcdefghijklmnopqrstuvwxyz0123456789',
12
+ '1-9': '0123456789',
13
+ 'A-z9': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
14
+ 'A-z9#': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+'
15
+ };
16
+ // Если ввели неизвестный код, используем полный набор по умолчанию
17
+ const characters = charsets[charsetType] || charsets['A-z9#'];
18
+ let result = '';
19
+ for (let i = 0; i < length; i++) {
20
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
21
+ }
22
+ return result;
23
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "pasaword",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "pasaword": "./dist/index.js"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "start": "node --no-warnings ./dist/index.js"
11
+ },
12
+ "dependencies": {
13
+ "chalk": "^5.3.0",
14
+ "cli-table3": "^0.6.3",
15
+ "clipboardy": "^5.3.0",
16
+ "commander": "^11.1.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^20.11.0",
20
+ "ts-node": "^10.9.2",
21
+ "typescript": "^5.3.3"
22
+ }
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+
3
+ import chalk from 'chalk';
4
+ import fs from 'fs';
5
+ import clipboard from 'clipboardy'; // Добавили библиотеку для буфера
6
+ import { generatePassword } from './logic.js';
7
+
8
+ const DB_PATH = './vault.json';
9
+
10
+ const readDB = () => JSON.parse(fs.readFileSync(DB_PATH, 'utf-8'));
11
+ const writeDB = (data: any) => fs.writeFileSync(DB_PATH, JSON.stringify(data, null, 2));
12
+ const clr1 = chalk.rgb(201, 204, 161);
13
+ const clr2 = chalk.rgb(202,160,90);
14
+ const clr3 = chalk.rgb(174,106,71);
15
+ const clr4 = chalk.rgb(139,64,73);
16
+ const clr5 = chalk.rgb(84,51,68);
17
+ const clr6 = chalk.rgb(81,82,98);
18
+ const clr7 = chalk.rgb(99,120,125);
19
+ const clr8 = chalk.rgb(142,160,145);
20
+ function showLogo() {
21
+ console.clear();
22
+
23
+ // Определяем цвета заранее, чтобы код был читабельным
24
+
25
+
26
+
27
+ console.log(`
28
+ ${clr1(' _______')} ${clr1('<-P-A-S-A-W-O-R-D->')}
29
+ ${clr1(' / ___ \\')}
30
+ ${clr2(' / / \\ \\')} ${clr2('v1.1.0 (Custom Engine)')}
31
+ ${clr3(' _| |_____| |_')} ${clr3('Author: Dv4c')}
32
+ ${clr4(' [ __ ]')}
33
+ ${clr5(' | / \\ |')}
34
+ ${clr6(' | | | |')}
35
+ ${clr7(' | |||| |')}
36
+ ${clr8(' |_____________|')}
37
+ `);
38
+ }
39
+
40
+ const args = process.argv.slice(2);
41
+ const command = args[0];
42
+
43
+ async function main() {
44
+ showLogo();
45
+
46
+ if (!command || command === '-h' || command === '--help') {
47
+ console.log('\n '+clr1('Options')+':');
48
+ console.log(` ${clr2('-l, --list').padEnd(25)} ${clr7('Show list with all saved info')}`);
49
+
50
+ console.log(` ${clr2('-g, --generate').padEnd(25)} ${clr7('Generate password : ') + clr3('<service> <login>') + clr3(' [type] [len]')}`);
51
+ console.log(' '+clr1('Default')+ ': ' + clr7('type') + clr7(' : ') + clr3('A-z9#') + ', ' + clr7('length') +clr7(' : ') + clr3('8'));
52
+ console.log(' '+clr1('Types') +': '+ clr3('A-Z, A-z, a-z, A-9, a-9, 1-9, A-z9, A-z9#'));
53
+
54
+ console.log(` ${clr2('-s, --save').padEnd(25)} ${clr7('Save manual password: ') + clr3('<service> <login> <pass>')}`);
55
+ console.log(` ${clr2('-cp, --copy').padEnd(25)} ${clr7('Copy password to clipboard: ') + clr3('<id>')}`);
56
+ console.log(` ${clr2('-d, --delete').padEnd(25)} ${clr7('Delete record by number: ') + clr3('<id>')}`);
57
+
58
+ console.log();
59
+ process.exit(0);
60
+ }
61
+
62
+ switch (command) {
63
+ case '-l':
64
+ case '--list':
65
+ const db = readDB();
66
+ // Названия столбцов в первый цвет (clr1)
67
+ console.log(clr1('\n ID SERVICE LOGIN PASSWORD'));
68
+ // Линии во второй цвет (clr2)
69
+ console.log(clr2(' ——————————————————————————————————————————'));
70
+
71
+ db.forEach((item: any, i: number) => {
72
+ // Номера (ID) — clr1
73
+ const id = clr1(String(i + 1).padEnd(3));
74
+ // Сервисы — clr2
75
+ const svc = clr2(item.service.padEnd(12));
76
+ // Логины — clr1
77
+ const log = clr1(item.login.padEnd(14));
78
+ // Пароли — clr2
79
+ const pass = clr2(item.password);
80
+
81
+ console.log(` ${id} ${svc} ${log} ${pass}`);
82
+ });
83
+
84
+ console.log(clr2(' ——————————————————————————————————————————'));
85
+
86
+ // Tips в clr1
87
+ console.log(clr1('\n Tips:'));
88
+ // Команда в clr2, Описание в clr3
89
+ console.log(` ${clr2('-cp, --copy').padEnd(25)} ${clr7('Copy password to clipboard:')} ${clr3('<id>')}`);
90
+ break;
91
+
92
+ case '-g':
93
+ case '--generate':
94
+ const svcGen = args[1];
95
+ const logGen = args[2];
96
+ const typeGen = args[3] || 'A-z9#';
97
+ const lenGen = parseInt(args[4]) || 8;
98
+
99
+ if (!svcGen || !logGen) {
100
+ console.log(chalk.red('\n [!] Error: Service and login are required!'));
101
+ return;
102
+ }
103
+
104
+ const genPass = generatePassword(lenGen, typeGen);
105
+ const dbGen = readDB();
106
+ dbGen.push({ service: svcGen, login: logGen, password: genPass });
107
+ writeDB(dbGen);
108
+ clipboard.writeSync(genPass);
109
+ console.log(chalk.blue(` [+] Generated (${typeGen}, len: ${lenGen}): ${clr7(genPass)}`));
110
+ console.log(clr2(` [✔] Saved and copied to clipboard!`));
111
+ break;
112
+
113
+ case '-s':
114
+ case '--save':
115
+ const svcSet = args[1];
116
+ const logSet = args[2];
117
+ const passSet = args[3];
118
+ if (!svcSet || !logSet || !passSet) {
119
+ console.log(chalk.red('\n [!] Error: Missing data!'));
120
+ return;
121
+ }
122
+ const dbSet = readDB();
123
+ dbSet.push({ service: svcSet, login: logSet, password: passSet });
124
+ writeDB(dbSet);
125
+ console.log(clr2(`\n [✔] Manual entry for ${svcSet} saved successfully!`));
126
+ break;
127
+
128
+ case '-cp':
129
+ case '--copy':
130
+ const idCp = parseInt(args[1]);
131
+ const dbCp = readDB();
132
+ if (dbCp[idCp - 1]) {
133
+ clipboard.writeSync(dbCp[idCp - 1].password);
134
+ console.log(clr2(`\n [✔] Password for ${chalk.bold(dbCp[idCp - 1].service)} copied to clipboard!`));
135
+ } else {
136
+ console.log(chalk.red('\n [!] Error: Record with this ID not found!'));
137
+ }
138
+ break;
139
+
140
+ case '-d':
141
+ case '--delete':
142
+ const id = parseInt(args[1]);
143
+ let list = readDB();
144
+ if (list[id - 1]) {
145
+ const removed = list.splice(id - 1, 1);
146
+ writeDB(list);
147
+ console.log(chalk.red(` [×] Deleted record for: ${removed[0].service}`));
148
+ } else {
149
+ console.log(chalk.red(' [!] Error: Record with this ID not found!'));
150
+ }
151
+ break;
152
+
153
+ default:
154
+ console.log(chalk.red(`\n [!] Unknown command: ${command}`));
155
+ }
156
+
157
+ }
158
+
159
+ main();
package/src/logic.ts ADDED
@@ -0,0 +1,25 @@
1
+ // src/logic.ts
2
+
3
+ /**
4
+ * Генерирует случайный пароль заданной длины
5
+ */
6
+ export function generatePassword(length: number = 8, charsetType: string = 'A-z9#'): string {
7
+ const charsets: Record<string, string> = {
8
+ 'A-Z': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
9
+ 'a-z': 'abcdefghijklmnopqrstuvwxyz',
10
+ 'A-z': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
11
+ 'A-9': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
12
+ 'a-9': 'abcdefghijklmnopqrstuvwxyz0123456789',
13
+ '1-9': '0123456789',
14
+ 'A-z9': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
15
+ 'A-z9#': 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+'
16
+ };
17
+
18
+ // Если ввели неизвестный код, используем полный набор по умолчанию
19
+ const characters = charsets[charsetType] || charsets['A-z9#'];
20
+ let result = '';
21
+ for (let i = 0; i < length; i++) {
22
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
23
+ }
24
+ return result;
25
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "strict": true,
10
+ "outDir": "./dist"
11
+ },
12
+ "include": ["src/**/*"]
13
+ }