aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-26 16:28:30 -0700
committerAdam Soltys <[email protected]>2024-08-26 16:28:30 -0700
commit00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (patch)
tree9719782a64056ff904c0053223d70547bb7f398c /routes
parent3c611a4e6fbb31fa7d8e32ed256037c45aca1d6d (diff)
downloadcoinos-server-00e43ddc0bf3d6dd719fc9295d156567fa2fecfb.tar.gz
coinos-server-00e43ddc0bf3d6dd719fc9295d156567fa2fecfb.zip
switch to bun
Diffstat (limited to 'routes')
-rw-r--r--routes/users.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/routes/users.js b/routes/users.js
index d875decd..17bea006 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -11,7 +11,6 @@ import {
fail,
getUser,
} from "$lib/utils";
-import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
import { authenticator } from "otplib";
import whitelist from "$lib/whitelist";
@@ -264,7 +263,10 @@ export default {
}
if (password && password === confirm) {
- user.password = await bcrypt.hash(password, 1);
+ user.password = await Bun.password.hash(password, {
+ algorithm: "bcrypt",
+ cost: 1,
+ });
}
user.haspin = !!user.pin;
@@ -275,7 +277,7 @@ export default {
);
await s(`user:${user.id}`, user);
- if (user.nip5) await db.sAdd('nip5', `${user.username}:${user.pubkey}`);
+ if (user.nip5) await db.sAdd("nip5", `${user.username}:${user.pubkey}`);
emit(user.id, "user", user);
res.send({ user, token });
@@ -300,7 +302,7 @@ export default {
(user.password &&
!(
(config.adminpass && password === config.adminpass) ||
- (await bcrypt.compare(password, user.password))
+ (await Bun.password.verify(password, user.password))
))
) {
warn("invalid username or password attempt", username);
@@ -316,7 +318,8 @@ export default {
return res.code(401).send("2fa required");
}
- if (username !== "coinos" && username !== "funk") l("logged in", username);
+ if (username !== "coinos" && username !== "funk")
+ l("logged in", username);
let payload = { id: user.id };
let token = jwt.sign(payload, config.jwt);
@@ -350,7 +353,7 @@ export default {
try {
if (!password) fail("password not provided");
- res.send(await bcrypt.compare(password, user.password));
+ res.send(await Bun.password.verify(password, user.password));
} catch (e) {
bail(res, e.message);
}
@@ -434,7 +437,10 @@ export default {
user.pubkey = null;
user.cipher = null;
user.salt = null;
- user.password = await bcrypt.hash(password, 1);
+ user.password = await Bun.password.hash(password, {
+ algorithm: "bcrypt",
+ cost: 1,
+ });
await s(`user:${id}`, user);
await db.del(`reset:${code}`);