UNPKG

814 BJavaScriptView Raw
1"use strict";
2
3// Importing crypto module.
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.md5 = md5;
9exports.encode = encode;
10
11var _crypto = require('crypto');
12
13var _crypto2 = _interopRequireDefault(_crypto);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17// md5 function.
18function md5(str) {
19 var hash = _crypto2.default.createHash('MD5');
20 hash.update(str);
21
22 return hash.digest('hex');
23}
24
25// encode function.
26function encode(program) {
27 // Prepare arguments.
28 var realm = program.args[1];
29 var username = program.args[2];
30 var password = program.args[3];
31
32 // Generate hash.
33 var hash = md5(username + ':' + realm + ':' + password);
34
35 // Final result.
36 return username + ':' + realm + ':' + hash;
37}
\No newline at end of file