public async Task <IActionResult> Login([FromBody] LoginDto loginDto) { try { var logMember = await _authServices.Login(loginDto.Username.ToLower(), loginDto.EmailAddress, loginDto.Password); if (logMember == null) { return(Unauthorized()); } //Generating Token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes("Super Secret Key"); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new System.Security.Claims.ClaimsIdentity(new Claim [] { new Claim(ClaimTypes.NameIdentifier, logMember.ID.ToString()), new Claim(ClaimTypes.Name, logMember.Username), new Claim(ClaimTypes.Email, loginDto.EmailAddress), }), Expires = DateTime.Now.AddDays(2), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); return(Ok(new { tokenString })); } catch (Exception) { return(StatusCode(400, "Error Processing this request, please contact the Administration")); } }