UNPKG

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