2020-03-04 12:20:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) Sapphirecode - All Rights Reserved
|
2020-05-17 17:23:22 +02:00
|
|
|
* This file is part of password-helper which is released under MIT.
|
2020-03-25 17:02:04 +01:00
|
|
|
* See file 'LICENSE' for full license details.
|
2020-05-17 17:23:22 +02:00
|
|
|
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
2020-03-04 12:20:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* eslint-disable no-magic-numbers */
|
|
|
|
'use strict';
|
|
|
|
|
2020-03-04 13:21:54 +01:00
|
|
|
const argon2 = require ('argon2');
|
2020-03-04 12:20:42 +01:00
|
|
|
|
|
|
|
const argon_options = {
|
|
|
|
hashLength: 64,
|
|
|
|
saltLength: 32,
|
|
|
|
type: argon2.argon2id
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* verify a plain text against an argon2 hash
|
|
|
|
*
|
2020-03-04 13:21:54 +01:00
|
|
|
* @param {string} hash_str hash
|
2020-03-04 12:20:42 +01:00
|
|
|
* @param {string} plain plain text
|
|
|
|
* @returns {Promise<boolean>} true if valid
|
|
|
|
*/
|
2020-03-04 13:21:54 +01:00
|
|
|
function verify (hash_str, plain) {
|
|
|
|
return argon2.verify (hash_str, plain, argon_options);
|
2020-03-04 12:20:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create an argon2 hash
|
|
|
|
*
|
|
|
|
* @param {string} plain plain text
|
|
|
|
* @returns {Promise<string>} hash
|
|
|
|
*/
|
2020-03-04 13:21:54 +01:00
|
|
|
function hash (plain) {
|
2020-03-04 12:20:42 +01:00
|
|
|
return argon2.hash (plain, argon_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-03-04 13:21:54 +01:00
|
|
|
hash,
|
|
|
|
verify
|
|
|
|
};
|