Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
310 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules | |
.idea | ||
htdigest.iml | ||
.settings | ||
src | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
require("../gensrc/htdigest"); | ||
var settings = require('../package.json'); | ||
require("../gensrc/htdigest").default(settings.version, process.argv); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// Importing local modules. | ||
import program from 'commander' | ||
import * as processor from './processor' | ||
|
||
// Parses and processes command line arguments. | ||
export default function(version, args) { | ||
// Setup. | ||
program | ||
.version(version) | ||
.usage("[options] passwordfile realm username") | ||
.option('-c, --create', "Create a new file."); | ||
|
||
// Help option. | ||
program.on('--help', function () { | ||
console.log(` | ||
Examples: | ||
htdigest [-c] passwordfile realm username | ||
`); | ||
}); | ||
|
||
// Parse options. | ||
program.parse(args); | ||
|
||
// Process program output. | ||
processor.exec(program); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"use strict"; | ||
|
||
// Utils. | ||
import * as utils from './utils' | ||
|
||
// FS. | ||
import fs from 'fs' | ||
|
||
// Prompt module. | ||
import prompt from 'prompt' | ||
|
||
// Sync file function. | ||
export function syncFile(program) { | ||
// Read params. | ||
let passwordFile = program.args[0]; | ||
let realm = program.args[1]; | ||
let username = program.args[2]; | ||
|
||
// Encode file data. | ||
let writeData = utils.encode(program); | ||
|
||
// Collectors. | ||
let found = false; | ||
let newLines = []; | ||
|
||
// Not creating file. | ||
if (!program.create) { | ||
// Check if file exists. | ||
if (!fs.existsSync(passwordFile)) { | ||
console.error(`Cannot modify file ${passwordFile}; use '-c' to create it.`); | ||
return | ||
} | ||
|
||
// Read lines. | ||
let lines = fs.readFileSync(passwordFile, 'UTF-8').split("\n"); | ||
|
||
// Loop lines. | ||
lines.forEach(line => { | ||
if (line.indexOf(`${username}:${realm}:`) === 0) { | ||
found = true; | ||
newLines.push(writeData); | ||
console.log(`Changing password for user ${username} in realm ${realm}.`); | ||
} else { | ||
newLines.push(line); | ||
} | ||
}); | ||
} | ||
|
||
// Adding user to existing file. | ||
if (!found) { | ||
newLines.push(writeData); | ||
console.log(`Adding password for user ${username} in realm ${realm}.`); | ||
} | ||
|
||
// Write data. | ||
fs.writeFileSync(passwordFile, newLines.join("\n") + "\n", 'UTF-8'); | ||
} | ||
|
||
// Read password. | ||
export function readPassword(program) { | ||
prompt.message = ""; | ||
prompt.delimiter = ""; | ||
|
||
let passportOption = [{name: 'password', description: 'New password:', hidden: true}]; | ||
let rePassportOption = [{name: 'rePassword', description: 'Re-type new password:', hidden: true}]; | ||
|
||
// Try to read password. | ||
setTimeout(function () { | ||
prompt.get(passportOption, function (err, result) { | ||
if (!err) { | ||
let password = result.password; | ||
setTimeout(function () { | ||
prompt.get(rePassportOption, function (err, result) { | ||
if (!err && password == result.rePassword) { | ||
program.args.push(password); | ||
|
||
try { | ||
syncFile(program); | ||
} catch (err) { | ||
console.error(err.message); | ||
} | ||
} else { | ||
console.error("\nPassword verification error."); | ||
} | ||
}); | ||
}, 50); | ||
} else { | ||
console.error("\nPassword verification error."); | ||
} | ||
}); | ||
}, 50); | ||
} | ||
|
||
// Process command. | ||
export function exec(program) { | ||
if (program.args.length === 3) { | ||
readPassword(program); | ||
} else { | ||
program.help(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use strict"; | ||
|
||
// Importing crypto module. | ||
import crypto from 'crypto' | ||
|
||
// md5 function. | ||
export function md5(str) { | ||
let hash = crypto.createHash('MD5'); | ||
hash.update(str); | ||
|
||
return hash.digest('hex'); | ||
} | ||
|
||
// encode function. | ||
export function encode(program) { | ||
// Prepare arguments. | ||
let realm = program.args[1]; | ||
let username = program.args[2]; | ||
let password = program.args[3]; | ||
|
||
// Generate hash. | ||
let hash = md5(`${username}:${realm}:${password}`); | ||
|
||
// Final result. | ||
return `${username}:${realm}:${hash}`; | ||
} |
Oops, something went wrong.