public ServiceOperationResult <string> Login(LoginForm form) { var user = _unitOfWork.Users .GetAsQueryable() .SingleOrDefault(u => u.Username == form.Username); if (user == null) { return(ServiceOperationResult.InvalidPassword <string>("Login/Password pair is invalid.")); } if (!PasswordHasher.VerifyPasswordHash(form.Password, user.PasswordHash, user.PasswordSalt)) { return(ServiceOperationResult.InvalidPassword <string>("Login/Password pair is invalid.")); } return(ServiceOperationResult.Ok( JwtTokenGenerator.GetTokenString( user, TimeSpan.FromDays(7), Encoding.ASCII.GetBytes(_configuration["AppSecret"]) ))); }