-
-
Save Sathasivamthirumoorthi/bf69f929333ef07d74a690b3b19ab9ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ServiceResponse<ResetPasswordDto>> ResetPassword(ResetPasswordDto request) | |
{ | |
ServiceResponse<ResetPasswordDto> response = new ServiceResponse<ResetPasswordDto>(); | |
// Check if the provided email is not null. | |
if (request.Email is not null) | |
{ | |
// Try to find a user with the given email in the database. | |
var user = await _dbContext.Users.FirstOrDefaultAsync( | |
u => u.Email!.ToLower() == request.Email.ToLower() | |
); | |
// Check if a user with the given email was found. | |
if (user != null) | |
{ | |
if (user.IsVerified == false) | |
{ | |
response.Success = false; | |
response.Message = "User Not Verified"; | |
return response; | |
} | |
if (user.OtpExpiration > DateTimeOffset.UtcNow) | |
{ | |
CreatePasswordHash( | |
request.NewPassword, | |
out byte[] passwordHash, | |
out byte[] passwordSalt | |
); | |
user.PasswordHash = passwordHash; | |
user.PasswordSalt = passwordSalt; | |
user.Otp = null; | |
user.OtpExpiration = null; | |
await _dbContext.SaveChangesAsync(); | |
response.Message = "Password changed successfully."; | |
} | |
else | |
{ | |
response.Success = false; | |
response.Message = "Your OTP is expired."; | |
return response; | |
} | |
} | |
else | |
{ | |
response.Success = false; | |
response.Message = "Invalid Email Address."; | |
} | |
} | |
else | |
{ | |
response.Success = false; | |
response.Message = "Email is Required."; | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment