Add a script to hash a password for user database.

This commit is contained in:
Clement Michaud 2019-02-22 10:59:42 +01:00
parent 5614bea827
commit 4bd7ea6f42
3 changed files with 29 additions and 1 deletions

View File

@ -12,6 +12,7 @@ program
.command('test', 'Run Authelia integration tests.') .command('test', 'Run Authelia integration tests.')
.command('unittest', 'Run Authelia integration tests.') .command('unittest', 'Run Authelia integration tests.')
.command('hash-password <password>', 'Hash a password with SSHA512.')
.command('build-docker', 'Build Docker image containing production version of Authelia.') .command('build-docker', 'Build Docker image containing production version of Authelia.')
.command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.') .command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.')
.parse(process.argv); .parse(process.argv);

View File

@ -0,0 +1,28 @@
#!/usr/bin/env node
var program = require('commander');
var RandomString = require("randomstring");
var Util = require("util");
var crypt = require("crypt3");
function ssha512(password, saltSize, rounds) {
// $6 means SHA512
const _salt = Util.format("$6$rounds=%d$%s", rounds,
RandomString.generate(saltSize));
const hash = crypt(password, _salt);
return Util.format("{CRYPT}%s", hash);
}
let password;
program
.option('-s, --salt <size>', 'The size of the salt to generate.')
.option('-r, --rounds <rounds>', 'The number of rounds.')
.arguments('<password>')
.action(function (_password) {
password = _password;
})
.parse(process.argv);
console.log(ssha512(password, program.salt || 16, program.rounds || 500000));

View File

@ -8,7 +8,6 @@ export class HashGenerator {
password: string, password: string,
rounds: number = 500000, rounds: number = 500000,
salt?: string): BluebirdPromise<string> { salt?: string): BluebirdPromise<string> {
const saltSize = 16;
// $6 means SHA512 // $6 means SHA512
const _salt = Util.format("$6$rounds=%d$%s", rounds, const _salt = Util.format("$6$rounds=%d$%s", rounds,
(salt) ? salt : RandomString.generate(16)); (salt) ? salt : RandomString.generate(16));