generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.ts
34 lines (34 loc) · 889 Bytes
/
cli.ts
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
/**
* @module scrypt/cli
* @author oplik0
* This is a simple CLI for the scrypt module. It doesn't export anything, but can be used as a standalone script.
*/
import { genSalt, hash, verify } from "./mod.ts";
/**
* @todo add a proper argument parser ([args](https://deno.land/x/args) perhaps?)
*/
if (import.meta.main) {
const args = Deno.args.slice();
const command = args.shift();
switch (command) {
case "hash":
for (const arg of args) {
console.log(hash(arg));
}
break;
case "verify":
console.log(verify(args[0], args[1]));
break;
case "salt":
if (args.length) {
for (const arg of args) {
console.log(genSalt(parseInt(arg, 10)));
}
} else {
console.log(genSalt());
}
break;
default:
console.log(`usage: hash <password>, verify <password>, <hash>`);
}
}