Update auth.js

This commit is contained in:
Wavering Ana 2022-11-16 05:05:26 -05:00 committed by GitHub
parent 1588e4f861
commit b054e3b310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,36 +64,4 @@ router.post('/logout', function(req, res, next) {
}); });
}); });
router.get('/signup', function(req, res, next) {
res.render('signup');
});
router.post('/signup', function(req, res, next) {
var salt = crypto.randomBytes(16);
crypto.pbkdf2(req.body.password, salt, 310000, 32, 'sha256', function(err, hashedPassword) {
if (err) {
return next(err);
}
db.run('INSERT INTO users (username, hashed_password, salt) VALUES (?, ?, ?)', [
req.body.username,
hashedPassword,
salt
], function(err) {
if (err) {
return next(err);
}
var user = {
id: this.lastID,
username: req.body.username
};
req.login(user, function(err) {
if (err) {
return next(err);
}
res.redirect('/');
});
});
});
});
module.exports = router; module.exports = router;