42 lines
799 B
JavaScript
42 lines
799 B
JavaScript
|
/*
|
||
|
* Copyright (C) Sapphirecode - All Rights Reserved
|
||
|
* Created by Timo Hocker <timo@scode.ovh>, March 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 argon hash
|
||
|
* @param {string} plain plain text
|
||
|
* @returns {Promise<boolean>} true if valid
|
||
|
*/
|
||
|
function argon_verify (hash, plain) {
|
||
|
return argon2.verify (hash, plain, argon_options);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* create an argon2 hash
|
||
|
*
|
||
|
* @param {string} plain plain text
|
||
|
* @returns {Promise<string>} hash
|
||
|
*/
|
||
|
function argon_hash (plain) {
|
||
|
return argon2.hash (plain, argon_options);
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
argon_hash,
|
||
|
argon_verify
|
||
|
}
|