This commit is contained in:
Shahrad Elahi
2024-05-29 19:48:49 +03:30
parent bd2ddbb08b
commit f0d675dc39
6 changed files with 43 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ export const env = createEnv({
server: {
STORAGE_PATH: z.string().default('/data/storage.pack'),
AUTH_SECRET: z.string().default(sha256(randomUUID())),
HASHED_PASSWORD: z.string().default(sha256('insecure-password')),
ADMIN_PASSWORD: z.string().default('insecure-password'),
// -----
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
ORIGIN: z.string().optional(),

View File

@@ -28,13 +28,10 @@ export const actions: Actions = {
return fail(400, { ok: false, message: 'Bad Request', form });
}
const { HASHED_PASSWORD } = env;
const { ADMIN_PASSWORD } = env;
const { password } = form.data;
const hashed = HASHED_PASSWORD.toLowerCase();
const receivedHashed = sha256(password).toLowerCase();
if (hashed !== receivedHashed) {
if (sha256(ADMIN_PASSWORD).toLowerCase() !== sha256(password).toLowerCase()) {
logger.debug('Action: Login: failed to validate password.');
return setError(form, 'password', 'Incorrect password.');
}