Fixed ldap auth bullshit!

This commit is contained in:
BurnyLlama 2022-01-23 17:49:27 +01:00
parent 8fc201f5f7
commit 78de2c8344

View File

@ -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!")