public async Task <UserLoginResponse> Login(UserLoginRequest userInfo) { if (userInfo.Login == null && userInfo.Password == null) { return(new UserLoginResponse { PlayerId = -1, PlayerNickName = "unknown" }); } var userTuple = await GetUserIdByLogin(userInfo.Login); if (userTuple.Item2 == -1) { return new UserLoginResponse { PlayerId = -1, PlayerNickName = userTuple.Item1 } } ; var isUserBanned = await _banService.CheckUserBan(userTuple.Item2); if (isUserBanned) { return new UserLoginResponse { PlayerId = userTuple.Item2, PlayerNickName = userTuple.Item1, IsBanned = true } } ; StringBuilder sb = new StringBuilder(_encrypter.Encrypted(userInfo.Password)); var salt = await GetSalt(userTuple.Item2); sb.Append(salt.Salt); var user = await GetUser(userInfo.Login, sb.ToString()); if (user == null) { return new UserLoginResponse { PlayerId = -1, PlayerNickName = "unknown" } } ; if (user.EmailConfirmed == false) { return new UserLoginResponse() { PlayerNickName = userTuple.Item1, EmailIsNotConfirmed = true } } ; var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(this._applicationSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()), new Claim(ClaimTypes.Role, Enum.GetName(typeof(RoleType), user.RoleType)) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var encryptToken = tokenHandler.WriteToken(token); var lastDatePassMod = await GetLastDateModifiedPassword(userTuple.Item2); var ask = (DateTime.Today - lastDatePassMod).TotalDays > _applicationSettings.PasswordChangePeriod; // send email notification if is different ip return(new UserLoginResponse { PlayerId = user.Id, PlayerNickName = user.Nick, Token = encryptToken, GameToken = user.GameToken, AskAboutChangePassword = ask }); }