diff --git a/scripts/authelia-scripts b/scripts/authelia-scripts index 42bb46ca..eab9e7b0 100755 --- a/scripts/authelia-scripts +++ b/scripts/authelia-scripts @@ -12,6 +12,7 @@ program .command('test', 'Run Authelia integration tests.') .command('unittest', 'Run Authelia integration tests.') + .command('hash-password ', 'Hash a password with SSHA512.') .command('build-docker', 'Build Docker image containing production version of Authelia.') .command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.') .parse(process.argv); diff --git a/scripts/authelia-scripts-hash-password b/scripts/authelia-scripts-hash-password new file mode 100755 index 00000000..e8e25d5c --- /dev/null +++ b/scripts/authelia-scripts-hash-password @@ -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 ', 'The size of the salt to generate.') + .option('-r, --rounds ', 'The number of rounds.') + .arguments('') + .action(function (_password) { + password = _password; + }) + .parse(process.argv); + +console.log(ssha512(password, program.salt || 16, program.rounds || 500000)); diff --git a/server/src/lib/utils/HashGenerator.ts b/server/src/lib/utils/HashGenerator.ts index e67de32b..a88a21e4 100644 --- a/server/src/lib/utils/HashGenerator.ts +++ b/server/src/lib/utils/HashGenerator.ts @@ -8,7 +8,6 @@ export class HashGenerator { password: string, rounds: number = 500000, salt?: string): BluebirdPromise { - const saltSize = 16; // $6 means SHA512 const _salt = Util.format("$6$rounds=%d$%s", rounds, (salt) ? salt : RandomString.generate(16));