start work migrating to bun

This commit is contained in:
waveringana 2023-09-22 03:53:04 -04:00
parent fbee7798ab
commit 89663c696f
10 changed files with 251 additions and 159 deletions

View file

@ -9,30 +9,33 @@ import {db, UserRow} from "../types/db";
const router = express.Router();
passport.use(new LocalStrategy(function verify(username, password, cb) {
db.get("SELECT * FROM users WHERE username = ?", [username], function(err: Error, row: UserRow) {
if (err) {
return cb(err);
}
try {
// Fetch user from database using better-sqlite3's synchronous API
const row = db.prepare("SELECT * FROM users WHERE username = ?").get(username) as UserRow;
if (!row) {
return cb(null, false, {
message: "Incorrect username or password."
});
}
crypto.pbkdf2(password, row.salt, 310000, 32, "sha256", function(err, hashedPassword) {
if (err) {
return cb(err);
}
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
return cb(null, false, {
message: "Incorrect username or password."
});
}
return cb(null, row);
});
});
// Synchronously hash the provided password with the stored salt
const hashedPassword = crypto.pbkdf2Sync(password, row.salt, 310000, 32, "sha256");
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
return cb(null, false, {
message: "Incorrect username or password."
});
}
return cb(null, row);
} catch (err) {
return cb(err);
}
}));
passport.serializeUser(function(user:User, cb) {
process.nextTick(function() {
cb(null, {