password-helper/index.js

44 lines
900 B
JavaScript
Raw Normal View History

2020-03-04 12:20:42 +01:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
2020-03-25 17:02:04 +01:00
* This file is part of Password-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
2020-03-04 12:20:42 +01:00
* Created by Timo Hocker <timo@scode.ovh>, March 2020
*/
/* 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
};