Jelszó módosítása

This commit is contained in:
2025-04-14 12:31:50 +02:00
parent 44e6719c3d
commit 29200ae418
18 changed files with 676 additions and 9 deletions
+48 -1
View File
@@ -208,7 +208,54 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<UserDTO> Authenticate2F2ChangePassword(string userName, string oldPassword, string newPassword, string code, string token2FA)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
var user = await _dbContext.Users
.Include(i => i.UserRoles)
.ThenInclude(i => i.Role)
.Where(w => w.UserName == userName && w.Active != false)
.FirstOrDefaultAsync();
if (user != null && PasswordHasher.VerifyPassword(user.PasswordHash, oldPassword))
{
if (CodeGenerator2F.ValidateToken2F(token2FA, userName, oldPassword, code))
{
user.PasswordHash = PasswordHasher.HashPassword(newPassword);
var userDTO = new UserDTO()
{
Id = user.Id,
UserName = user.UserName,
RoleDTO = new List<RoleDTO>(),
};
foreach (var item in user.UserRoles)
{
userDTO.RoleDTO.Add(new RoleDTO()
{
Id = item.Role.Id,
RoleName = item.Role.RoleName,
});
}
user.PasswordHash = PasswordHasher.HashPassword(newPassword);
user.JwtToken = GenerateJwtToken(userDTO);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
return retVal;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<UserDTO> AuthenticateNFC(string NFCCode)
{