Skip to content

Commit

Permalink
perf tweak: using BCrypt.Verify instead of HashPassword again
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroves committed Oct 25, 2023
1 parent 374038a commit 71464d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Conduit/Conduit.Web/Users/Handlers/GetCurrentUserHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public GetCurrentUserHandler(IAuthService authService, IUserDataService userData

public async Task<GetCurrentUserResult> Handle(GetCurrentUserRequest request, CancellationToken cancellationToken)
{
// TODO: the whole user could be put into a JWT token, which would mean a database call could be skipped

var usernameClaim = _authService.GetUsernameClaim(request.BearerToken);
if (usernameClaim.IsNotFound)
return new GetCurrentUserResult { IsInvalidToken = true };
Expand Down
4 changes: 1 addition & 3 deletions Conduit/Conduit.Web/Users/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public AuthService(IOptions<JwtSecrets> jwtSecrets)

public string GenerateJwtToken(string email, string username)
{
// TODO: put username in claim too?

var claims = new[]
{
new Claim(ClaimTypes.Email, email),
Expand All @@ -42,7 +40,7 @@ public string GenerateJwtToken(string email, string username)

public bool DoesPasswordMatch(string submittedPassword, string passwordFromDatabase, string passwordSalt)
{
return HashPassword(submittedPassword, passwordSalt) == passwordFromDatabase;
return BCrypt.Net.BCrypt.Verify(submittedPassword, passwordFromDatabase);
}

public string HashPassword(string password, string passwordSalt)
Expand Down

0 comments on commit 71464d4

Please sign in to comment.