Files
logbuch/lib/auth.ts
T
admin a75303f857 feat: Version 1.10.0 — DB-Zugriff auf PHP-Bridge (DB4js_all.php) umgestellt
- lib/db.ts entfernt, mysql2-Abhängigkeit gestrichen
- lib/phpdb.ts: HTTP-Client für alle DB-Operationen via DB4js_all.php
- Alle API-Routen und Server Actions auf phpdb.ts umgestellt
- compose.yml / docker-compose.prod.yml: MySQL/phpMyAdmin-Container entfernt
- app/api/DB4js_all.php/route.ts: Proxy für Statistik-AJAX-Calls
- Statistik-Grafik liest ab 2026 live aus logbuch statt StatistikJahre
- PHP 7.3-Kompatibilität: str_contains → strpos

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 08:48:15 +02:00

37 lines
1.1 KiB
TypeScript

import bcrypt from 'bcryptjs';
import { getBeoByKuerzel, getBeoByName } from './phpdb';
export type { Beo } from './phpdb';
import type { Beo } from './phpdb';
export async function getBeoByLogin(login: string): Promise<Beo | null> {
const byKuerzel = await getBeoByKuerzel(login);
if (byKuerzel) return byKuerzel;
return getBeoByName(login);
}
export async function verifyCredentials(
login: string,
password: string
): Promise<{ beo: Beo; valid: boolean } | null> {
const beo = await getBeoByLogin(login);
if (!beo) return null;
if (!beo.pw) {
const defaultPw = process.env.DEFAULT_PASSWORD;
if (!defaultPw) throw new Error('DEFAULT_PASSWORD Umgebungsvariable ist nicht gesetzt!');
return { beo, valid: password === defaultPw };
}
const valid = await bcrypt.compare(password, beo.pw);
return { beo, valid };
}
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, 12);
}
export function getBeoDisplayName(beo: Beo): string {
return beo.vorname ? `${beo.vorname} ${beo.name}` : beo.name;
}