Improve admin password hash
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
Printful,
|
Printful,
|
||||||
Webflow,
|
Webflow,
|
||||||
} from "@blade-and-brawn/commerce";
|
} from "@blade-and-brawn/commerce";
|
||||||
import { DEFAULT_NAME, env, log } from "./util";
|
import { DEFAULT_NAME, env, log, sha256Sum } from "./util";
|
||||||
import serverTiming from "@elysia/server-timing";
|
import serverTiming from "@elysia/server-timing";
|
||||||
import jwt from "@elysia/jwt";
|
import jwt from "@elysia/jwt";
|
||||||
import { CommerceService, WOrderStatusSchema } from "./services/commerce";
|
import { CommerceService, WOrderStatusSchema } from "./services/commerce";
|
||||||
@@ -122,7 +122,7 @@ export const app = new Elysia()
|
|||||||
|
|
||||||
// AUTHENTICATION
|
// AUTHENTICATION
|
||||||
.post("/auth/login", async ({ jwt, body, cookie: { auth } }) => {
|
.post("/auth/login", async ({ jwt, body, cookie: { auth } }) => {
|
||||||
const match = crypto.timingSafeEqual(Buffer.from(body.password, "hex"), Buffer.from(env.ADMIN_PASSWORD, "hex"));
|
const match = crypto.timingSafeEqual(sha256Sum(body.password), Buffer.from(env.ADMIN_PASSWORD, "hex"));
|
||||||
if (!match) throw status(401, "Invalid credentials");
|
if (!match) throw status(401, "Invalid credentials");
|
||||||
|
|
||||||
auth.set({
|
auth.set({
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import cluster from 'node:cluster';
|
import cluster from 'node:cluster';
|
||||||
|
import { createHash } from 'node:crypto';
|
||||||
import { pino } from 'pino';
|
import { pino } from 'pino';
|
||||||
|
|
||||||
export const log = pino({
|
export const log = pino({
|
||||||
@@ -46,3 +47,5 @@ function optionEnv(key: string, fallback: string = ""): string {
|
|||||||
};
|
};
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const sha256Sum = (s: string) => createHash("sha256").update(s).digest();
|
||||||
|
|||||||
Reference in New Issue
Block a user