Baustein 1: Server-Auth-Fix (Kapitel 10)
/api/auth/login und /api/auth/register akzeptierten zuvor jeden beliebigen Nutzernamen/Passwort und stellten ein gueltiges 30-Tage-JWT aus - konkrete, ausnutzbare Luecke bei echtem Deployment. - PasswordHasher (PBKDF2, Salt pro Nutzer) + UserStore (LiteDB) statt des ungeprueften Stubs - /api/auth/register ersatzlos entfernt (kein offener Registrierungs-Endpunkt fuer ein Einzel-/Familien-Deployment) - Neue Nutzer per CLI (dotnet LehrerApp.Api.dll create-user <name>), dokumentiert in docker/README.md - Neues Testprojekt LehrerApp.Api.Tests (bisher als einziges Projekt ohne Tests) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,19 +14,12 @@ public static class Endpoints
|
||||
|
||||
public static void MapAuthEndpoints(this WebApplication app, string secret)
|
||||
{
|
||||
app.MapPost("/api/auth/login", (LoginRequest req) =>
|
||||
app.MapPost("/api/auth/login", (LoginRequest req, UserStore store) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(req.Username) || string.IsNullOrWhiteSpace(req.Password))
|
||||
return Results.Unauthorized();
|
||||
// TODO: Passwort gegen DB prüfen
|
||||
return Results.Ok(new { token = Jwt(req.Username, secret), userId = req.Username });
|
||||
});
|
||||
|
||||
app.MapPost("/api/auth/register", (RegisterRequest req) =>
|
||||
{
|
||||
if (req.Password.Length < 12)
|
||||
return Results.BadRequest("Passwort mind. 12 Zeichen.");
|
||||
// TODO: User anlegen, Passwort hashen (BCrypt)
|
||||
if (!store.VerifyPassword(req.Username, req.Password))
|
||||
return Results.Unauthorized();
|
||||
return Results.Ok(new { token = Jwt(req.Username, secret), userId = req.Username });
|
||||
});
|
||||
}
|
||||
@@ -130,4 +123,3 @@ public static class Endpoints
|
||||
}
|
||||
|
||||
public record LoginRequest(string Username, string Password);
|
||||
public record RegisterRequest(string Username, string Password, string DisplayName);
|
||||
|
||||
Reference in New Issue
Block a user