public async Task <IActionResult> Login([FromBody] UserResource userRsc) { if (userRsc == null) { return(BadRequest("Invalid client request")); } var dbUser = (await this.userRepo.GetAll()).FirstOrDefault(a => a.Name == userRsc.Name); if (dbUser == null) { return(BadRequest("Username not found:" + userRsc.Name)); } var userSalt = HashGenerator.StringToByteArray(dbUser.Salt); var hashPwd = HashGenerator.GenerateSaltedHash(HashGenerator.EncodedStringToByteArray(userRsc.Password), userSalt); if (HashGenerator.Compare(hashPwd, HashGenerator.StringToByteArray(dbUser.Password))) { return(Ok(new { Token = this.tokenGenetator.Generate(dbUser) })); } else { return(Unauthorized()); } }