Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sathasivamthirumoorthi/e67ee544da47b9dce7ee2a50ea4573a1 to your computer and use it in GitHub Desktop.
Save Sathasivamthirumoorthi/e67ee544da47b9dce7ee2a50ea4573a1 to your computer and use it in GitHub Desktop.
Authrepository.cs
public async Task<ServiceResponse<string>> Login(string username, string password)
{
var response = new ServiceResponse<string>();
var user = await _dbContext.Users.FirstOrDefaultAsync(
u => u.UserName!.ToLower() == username.ToLower()
);
//If user is null response message as User not found
if (user == null)
{
response.Success = false;
response.Message = "User Not Found";
}
//If user is not null verify password and if returns false set response as Incorrect Password
else if (!VerifyPasswordHash(password, user.PasswordHash!, user.PasswordSalt!))
{
response.Success = false;
response.Message = "Incorrect Password";
}
else
{
//If the manager is appointed generate JWT Token if not return false
if (user.Role == UserRole.Manager)
{
var manager = await _dbContext.Managers.FindAsync(user.UserID);
if (manager.IsAppointed == false)
{
response.Success = false;
response.Message = "User Not Found";
return response;
}
}
response.Data = _jwtUtils.GenerateJwtToken(user);
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment