Skip to content

Commit 32ca9a0

Browse files
committed
feat: add password-hash command
1 parent 293512b commit 32ca9a0

4 files changed

Lines changed: 39 additions & 27 deletions

File tree

lib/commands/generate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export default class extends Command {
3131
"title": "Encrypt / decrypt data with SSH private key",
3232
"module": () => new URL( "generate/ssh.js", import.meta.url ),
3333
},
34-
"argon2": {
35-
"short": "a",
36-
"title": "Create / verify agron2 hash",
37-
"module": () => new URL( "generate/argon2.js", import.meta.url ),
34+
"password-hash": {
35+
"short": "h",
36+
"title": "Create / verify password hash",
37+
"module": () => new URL( "generate/password-hash.js", import.meta.url ),
3838
},
3939
},
4040
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export default class extends Command {
88
"commands": {
99
"create": {
1010
"short": "c",
11-
"title": "Create argon2 hash",
12-
"module": () => new URL( "argon2/create.js", import.meta.url ),
11+
"title": "Create password hash",
12+
"module": () => new URL( "password-hash/create.js", import.meta.url ),
1313
},
1414
"verify": {
1515
"short": "v",
16-
"title": "Verify argon2 hash",
17-
"module": () => new URL( "argon2/verify.js", import.meta.url ),
16+
"title": "Verify password hash",
17+
"module": () => new URL( "password-hash/verify.js", import.meta.url ),
1818
},
1919
},
2020
};
Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Argon2 from "#core/argon2";
1+
import PasswordHash from "#core/crypto/password-hash";
22
import Command from "#lib/command";
33

44
export default class extends Command {
@@ -9,43 +9,53 @@ export default class extends Command {
99
"options": {
1010
"preset": {
1111
"short": "P",
12-
"description": "Argon2 preset.",
13-
"default": Argon2.defaultPreset,
14-
"schema": { "enum": Object.keys( Argon2.presets ) },
15-
},
16-
"id": {
17-
"short": "i",
18-
"description": "Argon2 algorithm id.",
19-
"schema": { "enum": [ "argon2d", "argon2i", "argon2id" ] },
12+
"description": "Preset.",
13+
"default": PasswordHash.defaultPreset,
14+
"schema": { "enum": Object.keys( PasswordHash.presets ) },
2015
},
2116
"argon2-version": {
2217
"short": "v",
23-
"description": "Argon2 algorithm version.",
18+
"description": "(argon2) Algorithm version.",
2419
"schema": { "enum": [ 16, 19 ] },
2520
},
2621
"memory-cost": {
2722
"short": "m",
28-
"description": "Argon2 memory cost parameter in KiB.",
23+
"description": "(argon2) Memory cost parameter in KiB.",
2924
"schema": { "type": "integer", "minimum": 1, "maximum": 2 ** 32 - 1 },
3025
},
3126
"time-cost": {
3227
"short": "t",
33-
"description": "Argon2 time cost parameter.",
28+
"description": "(argon2) Time cost parameter.",
3429
"schema": { "type": "integer", "minimum": 1, "maximum": 2 ** 32 - 1 },
3530
},
3631
"parallelism": {
3732
"short": "p",
38-
"description": "Argon2 parallelism parameter.",
33+
"description": "(argon2, scrypt) Parallelism parameter.",
3934
"schema": { "type": "integer", "minimum": 1, "maximum": 255 },
4035
},
36+
"cost": {
37+
"short": "c",
38+
"description": "(scrypt) Cost parameter.",
39+
"schema": { "type": "integer", "minimum": 2 },
40+
},
41+
"block-size": {
42+
"short": "b",
43+
"description": "(scrypt) Block size parameter.",
44+
"schema": { "type": "integer", "minimum": 2 },
45+
},
46+
"iterations": {
47+
"short": "i",
48+
"description": "(pbkdf2) Iterations parameter.",
49+
"schema": { "type": "integer", "minimum": 1 },
50+
},
4151
"salt-length": {
4252
"short": "s",
43-
"description": "Argon2 salt length.",
53+
"description": "Salt length.",
4454
"schema": { "type": "integer", "minimum": 8, "maximum": 48 },
4555
},
4656
"hash-length": {
4757
"short": "h",
48-
"description": "Argon2 hash length.",
58+
"description": "Hash length.",
4959
"schema": { "type": "integer", "minimum": 12, "maximum": 64 },
5060
},
5161
},
@@ -61,18 +71,20 @@ export default class extends Command {
6171

6272
// public
6373
async run () {
64-
const argon2 = new Argon2( {
74+
const passwordHash = new PasswordHash( {
6575
"preset": process.cli.options.preset,
66-
"id": process.cli.options.id,
6776
"version": process.cli.options[ "argon2-version" ],
6877
"memoryCost": process.cli.options[ "memory-cost" ],
6978
"timeCost": process.cli.options[ "time-cost" ],
7079
"parallelism": process.cli.options[ "parallelism" ],
80+
"cost": process.cli.options[ "cost" ],
81+
"blockSize": process.cli.options[ "block-size" ],
82+
"iterations": process.cli.options[ "iterations" ],
7183
"saltLength": process.cli.options[ "salt-length" ],
7284
"hashLength": process.cli.options[ "hash-length" ],
7385
} ),
74-
hash = await argon2.createHash( process.cli.arguments.password );
86+
hash = await passwordHash.createHash( process.cli.arguments.password );
7587

76-
console.log( hash );
88+
console.log( hash.phc );
7789
}
7890
}
File renamed without changes.

0 commit comments

Comments
 (0)