Added password inputs on registration screen.
Fix case where db is deleted but password hash still remains which causes user to never register. Allow password to have symbols and other characters. Added more tests. Moved passHash from config into the sqlite db. We can do this because we assume if sql failed to initialise then the key provided was wrong and thus we can show the user the password page.pull/77/head
parent
08ebc63fb0
commit
f53bec38a5
@ -1,9 +1,23 @@
|
||||
const { sha512 } = require('js-sha512');
|
||||
|
||||
const generateHash = (phrase) => sha512(phrase);
|
||||
const matchesHash = (phrase, hash) => sha512(phrase) === hash;
|
||||
const generateHash = (phrase) => phrase && sha512(phrase.trim());
|
||||
const matchesHash = (phrase, hash) => phrase && sha512(phrase.trim()) === hash.trim();
|
||||
|
||||
const validatePassword = (phrase) => {
|
||||
if (typeof phrase !== 'string') {
|
||||
return 'Password must be a string'
|
||||
}
|
||||
|
||||
if (phrase && phrase.trim().length < 6) {
|
||||
return 'Password must be atleast 6 characters long';
|
||||
}
|
||||
|
||||
// An empty password is still valid :P
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateHash,
|
||||
matchesHash,
|
||||
generateHash,
|
||||
matchesHash,
|
||||
validatePassword,
|
||||
};
|
Loading…
Reference in New Issue