diff --git a/routes/auth.js b/routes/auth.js index 7edbe68..a7cb720 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -7,6 +7,20 @@ import execawait from '../libs/execawait.js' const AUTH = Router() let valid = {} +/** + * ... + * @param {string} hash The hash to be converted to hex. + * @returns {string} hex of hash + */ +function hash2hex(hash) { + return hash + .split('') + .map(e => e + .charCodeAt(0) + .toString(16) + ) + .join('') +} AUTH.post('/register', async (req, res) => { const { captcha, password, username } = req.body @@ -36,9 +50,10 @@ AUTH.post('/register', async (req, res) => { bcrypt.hash(password, 10).then( hash => { + const hexHash = hash2hex(hash) glauth.query( - "INSERT INTO users(name, primarygroup, passbcrypt) VALUES($1::text, 0, $2::text)", - [ username, hash ] + "INSERT INTO users(name, primarygroup, passbcrypt, qam_pass) VALUES($1::text, 0, $2::text, $3::text)", + [ username, hexHash, hash ] ).then( () => res.send("Account registered!") ).catch( @@ -61,7 +76,7 @@ AUTH.post('/login', async (req, res) => { if (!user) return(res.send("User doesn't exist!")) - bcrypt.compare(password, user.passbcrypt).then( + bcrypt.compare(password, user.qam_pass).then( match => { if (!match) return res.send("Password's is incorrect!")