Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Mirch
Created March 24, 2019 19:35
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 Mirch/ceb7d4491ab4fbcb62e3855b8969ee61 to your computer and use it in GitHub Desktop.
Save Mirch/ceb7d4491ab4fbcb62e3855b8969ee61 to your computer and use it in GitHub Desktop.
[HttpPost("login")]
public IActionResult Login([FromBody]UserCredentials credentials)
{
var user = _context.Users.SingleOrDefault(u => u.Email == credentials.Email);
if (user != null)
{
var hashedPassword = _hashingService.Hash(credentials.Password, user.Salt);
if (hashedPassword == user.HashedPassword)
{
return Ok(BuildToken(user.Email));
}
}
return BadRequest("Could not login.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment