1 | "use strict";
|
2 |
|
3 |
|
4 | const crypto = require('crypto');
|
5 |
|
6 |
|
7 | const utils = {};
|
8 |
|
9 |
|
10 | utils.md5 = (str) => {
|
11 | let hash = crypto.createHash('MD5');
|
12 | hash.update(str);
|
13 |
|
14 | return hash.digest('hex');
|
15 | };
|
16 |
|
17 |
|
18 | utils.encode = (program) => {
|
19 |
|
20 | const realm = program.args[1];
|
21 | const username = program.args[2];
|
22 | const password = program.args[3];
|
23 |
|
24 |
|
25 | const hash = utils.md5(`${username}:${realm}:${password}`);
|
26 |
|
27 |
|
28 | return `${username}:${realm}:${hash}`;
|
29 | };
|
30 |
|
31 |
|
32 | module.exports = utils; |
\ | No newline at end of file |