Huge updates
This commit is contained in:
@@ -55,6 +55,26 @@ public class AuthService(IDbContextFactory<TimetrackerDbContext> factory, UserNo
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<string?> ChangePasswordAsync(int userId, string currentPassword, string newPassword)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6)
|
||||
return "Passwort muss mindestens 6 Zeichen lang sein.";
|
||||
|
||||
await using var db = await factory.CreateDbContextAsync();
|
||||
var user = await db.Users.FindAsync(userId);
|
||||
if (user == null) return "Benutzer nicht gefunden.";
|
||||
|
||||
if (!VerifyPassword(currentPassword, user.PasswordHash, user.PasswordSalt))
|
||||
return "Das aktuelle Passwort ist nicht korrekt.";
|
||||
|
||||
var (hash, salt) = HashPassword(newPassword);
|
||||
user.PasswordHash = hash;
|
||||
user.PasswordSalt = salt;
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<(User? User, string? Error)> RegisterAsync(string username, string password, string? honeypot = null) {
|
||||
if (string.IsNullOrWhiteSpace(username) || username.Length < 3)
|
||||
return (null, "Benutzername muss mindestens 3 Zeichen lang sein.");
|
||||
|
||||
Reference in New Issue
Block a user