From 1472ae922cac9af0e0d1a48a0ed469fb288a5174 Mon Sep 17 00:00:00 2001 From: "Akshay\" (aider)" Date: Sat, 9 Nov 2024 10:15:33 +0000 Subject: refactor: Use native Bun API for hashing passwords instead of bcrypt --- src/routes/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/routes/index.js b/src/routes/index.js index 5c04a6e..957746e 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,6 +1,6 @@ const express = require("express"); const he = require("he"); -const bcrypt = require("bcrypt"); +const { hash, compare } = require("bun"); const router = express.Router(); const geddit = require("../geddit.js"); const { db } = require("../index"); @@ -87,7 +87,7 @@ router.post("/register", async (req, res) => { return res.status(400).send("Passwords do not match"); } try { - const hashedPassword = await bcrypt.hash(password, 10); + const hashedPassword = await hash(password); db.query("INSERT INTO users (username, password_hash) VALUES (?, ?)", [ username, hashedPassword, @@ -105,7 +105,7 @@ router.post("/login", async (req, res) => { const user = db .query("SELECT * FROM users WHERE username = ?", [username]) .get(); - if (user && await bcrypt.compare(password, user.password_hash)) { + if (user && await compare(password, user.password_hash)) { res.status(200).redirect("/"); } else { res.status(401).send("Invalid credentials"); -- cgit v1.2.3