You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const { sha512 } = require('js-sha512');
|
|
|
|
|
|
|
|
const generateHash = (phrase) => phrase && sha512(phrase.trim());
|
|
|
|
const matchesHash = (phrase, hash) => phrase && sha512(phrase.trim()) === hash.trim();
|
|
|
|
|
|
|
|
const validatePassword = (phrase, i18n) => {
|
|
|
|
if (typeof phrase !== 'string') {
|
|
|
|
return i18n ? i18n('passwordTypeError') : 'Password must be a string'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phrase && phrase.trim().length < 6) {
|
|
|
|
return i18n ? i18n('passwordLengthError') : 'Password must be atleast 6 characters long';
|
|
|
|
}
|
|
|
|
|
|
|
|
// An empty password is still valid :P
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
generateHash,
|
|
|
|
matchesHash,
|
|
|
|
validatePassword,
|
|
|
|
};
|