-
Notifications
You must be signed in to change notification settings - Fork 502
Expand file tree
/
Copy pathbcrypt-password.js
More file actions
executable file
·59 lines (54 loc) · 1.66 KB
/
bcrypt-password.js
File metadata and controls
executable file
·59 lines (54 loc) · 1.66 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
#!/usr/bin/env node
'use strict';
/** small helper script to generate a bcrypt hashed password from plain text password
* Example:
* <code>
* $ export HTTP_PASSWORD_HASH=$(bcrypt-password.js -p myplainpass)
* $ echo $HTTP_PASSWORD_HASH
* $2b$10$BQPbC8dlxeEqB/nXOkyjr.tlafGZ28J3ug8sWIMRoeq5LSVOXpl3W
*
* or
* $ bcrypt-password.js -p myplainpass > my-secrets-file
* $ cat my-secrets-file
* $2b$10$BQPbC8dlxeEqB/nXOkyjr.tlafGZ28J3ug8sWIMRoeq5LSVOXpl3W
* </code>
*
* This generated password can be given to redis commander as a password-hash file
* (param "--http-auth-password-hash") or set as env var "HTTP_PASSWORD_HASH".
*
* Additionally the docker container of redis commander is reading the hashed
* http auth password from a secrets file too.
*/
const yargs = require('yargs');
let bcrypt;
try {
bcrypt = require('bcrypt');
// console.debug('using native bcrypt implementation');
} catch (e) {
bcrypt = require('bcryptjs');
// console.debug('using javascript bcryptjs implementation');
}
let args = yargs
.alias('h', 'help')
.alias('h', '?')
.options('password', {
alias: 'p',
type: 'string',
describe: 'The plain text password to hash'
})
.check(function(value) {
if (typeof value['password'] === 'undefined' || value['password'].trim() === '') {
console.error('password parameter missing and must not be empty');
console.error('usage: bcrypt-password.js -p <mysecretpass>');
process.exit(-1);
}
return true;
})
.usage('Usage: $0 [options]')
.wrap(yargs.terminalWidth())
.argv;
if (args.help) {
yargs.help();
return process.exit(0);
}
console.log(bcrypt.hashSync(args['password'], 10));