password-helper/index.js
2020-05-17 17:23:22 +02:00

44 lines
898 B
JavaScript

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