Fix login null check order and strengthen password reset code

- Reorder null check: check user != null before accessing user.IsDeleted
- Increase password reset code from 4 digits to 6 digits (10K to 1M combinations)
This commit is contained in:
Adam Moussa 2026-04-16 16:33:09 -04:00
parent 486233076c
commit 128ae44a0d

View file

@ -35,7 +35,7 @@ namespace Api.SeaHavenIndustries.Controllers
public async Task<IActionResult> Login([FromBody] LoginModel model)
{
var user = await _userManager.FindByNameAsync(model.Username ?? "");
if (user.IsDeleted != true && user != null && await _userManager.CheckPasswordAsync(user, model.Password ?? ""))
if (user != null && user.IsDeleted != true && await _userManager.CheckPasswordAsync(user, model.Password ?? ""))
{
// Standard login without 2FA
var userRoles = await _userManager.GetRolesAsync(user);
@ -214,7 +214,7 @@ namespace Api.SeaHavenIndustries.Controllers
private Random _random = new Random();
private string GenerateRandomNo()
{
return _random.Next(0, 9999).ToString("D4");
return _random.Next(0, 999999).ToString("D6");
}
#endregion
}