@page "/sys/click/resetpw/{userid}/{hash}" @using System.ComponentModel.DataAnnotations @using ImageBoardServerApp.Data.Repository @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navManager Password reset Password reset for account id #@userid



@if (msg != null) { @msg }
@code { private string Password { get; set; } private string msg { get; set; } [Parameter] [Required] public string userid { get; set; } [Parameter] [Required] public string hash { get; set; } public async void reset() { if (!int.TryParse(userid, out _)) { msg = "malformed userid."; return; } Console.WriteLine("Resetting a password..."); var user = await UsersRepository.getUserByIdAsync(int.Parse(userid)); if (user == null) { msg = "This user does not exist."; return; } if (user.ResetPasswordToken != hash) { msg = "The token does not match the account."; return; } if (user.ResetPasswordExpiresAt < 0 || user.ResetPasswordToken == "-1") { msg = "There is currently no valid link to reset this accounts password."; return; } if (user.ResetPasswordExpiresAt < DateTimeOffset.Now.ToUnixTimeMilliseconds()) { msg = "This link has expired."; return; } user.Password = Password = BCrypt.Net.BCrypt.HashPassword(Password); user.ResetPasswordToken = "-1"; user.ResetPasswordExpiresAt = -1; await UsersRepository.updateUserAsync(user); msg = "Your Password has been updated."; } }