mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Uses the crypt() function to do password encryption. This function handles several schemes such as: MD5, Blowfish, SHA1, SHA2. SHA-512 is used in Authelia for best security. The algorithm is fully described in https://www.akkadia.org/drepper/SHA-crypt.txt The 'crypt3' npm package has been added as a dependency to use the crypt() function. The package needs to be compiled in order to call the c function, that's why python, make and C++ compiler are installed temporarily in the Docker image.
21 lines
693 B
TypeScript
21 lines
693 B
TypeScript
import BluebirdPromise = require("bluebird");
|
|
import RandomString = require("randomstring");
|
|
import Util = require("util");
|
|
const crypt = require("crypt3");
|
|
|
|
export class HashGenerator {
|
|
static ssha512(password: string, salt?: string): BluebirdPromise<string> {
|
|
const rounds = 500000;
|
|
const saltSize = 16;
|
|
// $6 means SHA512
|
|
const _salt = Util.format("$6$rounds=%d$%s", rounds,
|
|
(salt) ? salt : RandomString.generate(16));
|
|
|
|
const cryptAsync = BluebirdPromise.promisify<string, string, string>(crypt);
|
|
|
|
return cryptAsync(password, _salt)
|
|
.then(function (hash: string) {
|
|
return BluebirdPromise.resolve(Util.format("{CRYPT}%s", hash));
|
|
});
|
|
}
|
|
} |