Exemplo n.º 1
0
        private async Task FinishLogin(bool isBiometricLogin, bool useHiddenField = false)
        {
            try
            {
                var userName = useHiddenField ? HiddenEmail : UserEmail;
                var password = useHiddenField ? HiddenPassword : UserPassword;
                IsLoggingIn = true;
                if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                {
                    throw new Exception("Not connected to Internet");
                }
                await Services.DataAccess.Login(userName, password);

                Preferences.Set("IsFirstLogin", false);
#if !DEBUG
                if (!isBiometricLogin)
                {
                    //the values are encrypted, encryption key stored in keychain/key store
                    await SecureStorage.SetAsync("UserName", UserEmail);

                    await SecureStorage.SetAsync("Password", UserPassword);

                    Preferences.Set("IsBiometricAuthEnabled", IsBiometricsEnabled);
                }
#endif
                List <Task> tasks = new List <Task>();
                if (App.Buildings is null || !App.Buildings.Any())
                {
                    tasks.Add(Services.DataAccess.GetBuildings());
                }
                if (App.BankAccounts is null || !App.BankAccounts.Any())
                {
                    tasks.Add(Services.DataAccess.GetBankAccounts());
                }
                if (App.Categories is null || App.Categories.Count == 0)
                {
                    tasks.Add(Services.DataAccess.GetAllCategoriesAndTags());
                    tasks.Add(Services.DataAccess.GetAllUsers());
                }
                await Task.WhenAll(tasks);

                OnSuccessfulLogin?.Invoke(this, true);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                await CoreMethods.DisplayAlert("ManageGo", ex.Message, "DISMISS");
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
Exemplo n.º 2
0
    private void SuccessAuthorization(AuthToken token, Action <AuthToken> success = null)
    {
        Debug.Log($"SUCCESS Token = {token}");
        if (rememberMeChkBox.isOn)
        {
            AuthTokenHelper.SaveToken(Constants.LAST_SUCCESS_AUTH_TOKEN, token);
        }
        else
        {
            AuthTokenHelper.DeleteToken(Constants.LAST_SUCCESS_AUTH_TOKEN);
        }

        success?.Invoke(token);
        OnSuccessfulLogin?.Invoke(token);
    }
Exemplo n.º 3
0
 private void OnSuccessfulLogin(OnSuccessfulLogin onSuccessfulLogin)
 {
     if (this._workSpaceViewModel.HasVerifiedPinCode())
     {
         this._workSpaceViewModel.UpdateState();
     }
     else
     {
         DispatcherHelper.CheckBeginInvokeOnUI((Action)(() =>
         {
             this.StateViewModel.UpdateActiveView(ViewState.Workspace);
             this.CurrentViewModel = (IBaseViewModel)this._workSpaceViewModel;
         }));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// This method verifies the login information sent by
        /// the client, and returns encrypted data for the client
        /// to verify as well
        /// </summary>
        public void ProcessLogin(Dictionary <string, string> Recv)
        {
            // Make sure we have all the required data to process this login
            if (!Recv.ContainsKey("uniquenick") || !Recv.ContainsKey("challenge") || !Recv.ContainsKey("response"))
            {
                Stream.SendAsync(@"\error\\err\0\fatal\\errmsg\Invalid Query!\id\1\final\");
                Disconnect(DisconnectReason.InvalidLoginQuery);
                return;
            }

            // Dispose connection after use
            try
            {
                using (GamespyDatabase Conn = new GamespyDatabase())
                {
                    // Try and fetch the user from the database
                    Dictionary <string, object> User = Conn.GetUser(Recv["uniquenick"]);
                    if (User == null)
                    {
                        Stream.SendAsync(@"\error\\err\265\fatal\\errmsg\The uniquenick provided is incorrect!\id\1\final\");
                        Disconnect(DisconnectReason.InvalidUsername);
                        return;
                    }

                    // Check if user is banned
                    bool banned = Int32.Parse(User["permban"].ToString()) > 0;
                    if (banned)
                    {
                        Stream.SendAsync(@"\error\\err\265\fatal\\errmsg\You account has been permanently suspended.\id\1\final\");
                        Disconnect(DisconnectReason.PlayerIsBanned);
                        return;
                    }

                    // Set player variables
                    PlayerId          = Int32.Parse(User["id"].ToString());
                    PlayerNick        = Recv["uniquenick"];
                    PlayerEmail       = User["email"].ToString();
                    PlayerCountryCode = User["country"].ToString();
                    PasswordHash      = User["password"].ToString().ToLowerInvariant();

                    // Use the GenerateProof method to compare with the "response" value. This validates the given password
                    if (Recv["response"] == GenerateProof(Recv["challenge"], ServerChallengeKey))
                    {
                        // Create session key
                        SessionKey = Crc.ComputeChecksum(PlayerNick);

                        // Password is correct
                        Stream.SendAsync(
                            @"\lc\2\sesskey\{0}\proof\{1}\userid\{2}\profileid\{2}\uniquenick\{3}\lt\{4}__\id\1\final\",
                            SessionKey,
                            GenerateProof(ServerChallengeKey, Recv["challenge"]), // Do this again, Params are reversed!
                            PlayerId,
                            PlayerNick,
                            GenerateRandomString(22) // Generate LT whatever that is (some sort of random string, 22 chars long)
                            );

                        // Log Incoming Connections
                        ServerManager.Log("Client Login:   {0} - {1} - {2}", PlayerNick, PlayerId, RemoteEndPoint);

                        // Update status last, and call success login
                        Status = LoginStatus.Completed;
                        CompletedLoginProcess = true;
                        OnSuccessfulLogin?.Invoke(this);
                    }
                    else
                    {
                        // Log Incoming Connections
                        ServerManager.Log("Failed Login Attempt: {0} - {1} - {2}", PlayerNick, PlayerId, RemoteEndPoint);

                        // Password is incorrect with database value
                        Stream.SendAsync(@"\error\\err\260\fatal\\errmsg\The password provided is incorrect.\id\1\final\");
                        Disconnect(DisconnectReason.InvalidPassword);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.GenerateExceptionLog(ex);
                Disconnect(DisconnectReason.GeneralError);
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method verifies the login information sent by
        /// the client, and returns encrypted data for the client
        /// to verify as well
        /// </summary>
        public void ProcessLogin(Dictionary <string, string> Recv)
        {
            uint partnerID = 0;

            // Make sure we have all the required data to process this login
            if (!Recv.ContainsKey("challenge") || !Recv.ContainsKey("response"))
            {
                PresenceServer.SendError(Stream, 0, "Invalid response received from the client!");
                Disconnect(DisconnectReason.InvalidLoginQuery);
                return;
            }

            // Parse the partnerid, required since it changes the challenge for Unique nick and User login
            if (Recv.ContainsKey("partnerid"))
            {
                if (!uint.TryParse(Recv["partnerid"], out partnerID))
                {
                    partnerID = 0;
                }
            }

            // Parse the 3 login types information
            if (Recv.ContainsKey("uniquenick"))
            {
                PlayerUniqueNick = Recv["uniquenick"];
            }
            else if (Recv.ContainsKey("authtoken"))
            {
                PlayerAuthToken = Recv["authtoken"];
            }
            else if (Recv.ContainsKey("user"))
            {
                // "User" is <nickname>@<email>
                string User = Recv["user"];
                int    Pos  = User.IndexOf('@');
                PlayerNick  = User.Substring(0, Pos);
                PlayerEmail = User.Substring(Pos + 1);
            }

            // Dispose connection after use
            try
            {
                // Try and fetch the user from the database
                Dictionary <string, object> QueryResult;

                try
                {
                    if (PlayerUniqueNick != null)
                    {
                        QueryResult = DatabaseUtility.GetUserFromUniqueNick(databaseDriver, Recv["uniquenick"]);
                    }
                    else if (PlayerAuthToken != null)
                    {
                        //TODO! Add the database entry
                        PresenceServer.SendError(Stream, 0, "AuthToken is not supported yet");
                        return;
                    }
                    else
                    {
                        QueryResult = DatabaseUtility.GetUserFromNickname(databaseDriver, PlayerEmail, PlayerNick);
                    }
                }
                catch (Exception)
                {
                    PresenceServer.SendError(Stream, 4, "This request cannot be processed because of a database error.");
                    return;
                }

                if (QueryResult == null)
                {
                    if (PlayerUniqueNick != null)
                    {
                        PresenceServer.SendError(Stream, 265, "The unique nickname provided is incorrect!");
                    }
                    else
                    {
                        PresenceServer.SendError(Stream, 265, "The nickname provided is incorrect!");
                    }

                    Disconnect(DisconnectReason.InvalidUsername);
                    return;
                }

                // Check if user is banned
                PlayerStatus currentPlayerStatus;
                UserStatus   currentUserStatus;

                if (!Enum.TryParse(QueryResult["status"].ToString(), out currentPlayerStatus))
                {
                    PresenceServer.SendError(Stream, 265, "Invalid player data! Please contact an administrator.");
                    Disconnect(DisconnectReason.InvalidPlayer);
                    return;
                }

                if (!Enum.TryParse(QueryResult["userstatus"].ToString(), out currentUserStatus))
                {
                    PresenceServer.SendError(Stream, 265, "Invalid player data! Please contact an administrator.");
                    Disconnect(DisconnectReason.InvalidPlayer);
                    return;
                }

                // Check the status of the account.
                // If the single profile is banned, the account or the player status

                if (currentPlayerStatus == PlayerStatus.Banned)
                {
                    PresenceServer.SendError(Stream, 265, "Your profile has been permanently suspended.");
                    Disconnect(DisconnectReason.PlayerIsBanned);
                    return;
                }

                if (currentUserStatus == UserStatus.Created)
                {
                    PresenceServer.SendError(Stream, 265, "Your account is not verified. Please check your email inbox and verify the account.");
                    Disconnect(DisconnectReason.PlayerIsBanned);
                    return;
                }

                if (currentUserStatus == UserStatus.Banned)
                {
                    PresenceServer.SendError(Stream, 265, "Your account has been permanently suspended.");
                    Disconnect(DisconnectReason.PlayerIsBanned);
                    return;
                }

                // Set player variables
                PlayerId          = uint.Parse(QueryResult["profileid"].ToString());
                PasswordHash      = QueryResult["password"].ToString().ToLowerInvariant();
                PlayerCountryCode = QueryResult["countrycode"].ToString();

                PlayerFirstName      = QueryResult["firstname"].ToString();
                PlayerLastName       = QueryResult["lastname"].ToString();
                PlayerICQ            = int.Parse(QueryResult["icq"].ToString());
                PlayerHomepage       = QueryResult["homepage"].ToString();
                PlayerZIPCode        = QueryResult["zipcode"].ToString();
                PlayerLocation       = QueryResult["location"].ToString();
                PlayerAim            = QueryResult["aim"].ToString();
                PlayerOwnership      = int.Parse(QueryResult["ownership1"].ToString());
                PlayerOccupation     = int.Parse(QueryResult["occupationid"].ToString());
                PlayerIndustryID     = int.Parse(QueryResult["industryid"].ToString());
                PlayerIncomeID       = int.Parse(QueryResult["incomeid"].ToString());
                PlayerMarried        = int.Parse(QueryResult["marriedid"].ToString());
                PlayerChildCount     = int.Parse(QueryResult["childcount"].ToString());
                PlayerConnectionType = int.Parse(QueryResult["connectiontype"].ToString());
                PlayerPicture        = int.Parse(QueryResult["picture"].ToString());
                PlayerInterests      = int.Parse(QueryResult["interests1"].ToString());
                PlayerBirthday       = ushort.Parse(QueryResult["birthday"].ToString());
                PlayerBirthmonth     = ushort.Parse(QueryResult["birthmonth"].ToString());
                PlayerBirthyear      = ushort.Parse(QueryResult["birthyear"].ToString());

                PlayerSexType playerSexType;
                if (!Enum.TryParse(QueryResult["sex"].ToString().ToUpper(), out playerSexType))
                {
                    PlayerSex = PlayerSexType.PAT;
                }
                else
                {
                    PlayerSex = playerSexType;
                }

                PlayerLatitude   = float.Parse(QueryResult["latitude"].ToString());
                PlayerLongitude  = float.Parse(QueryResult["longitude"].ToString());
                PlayerPublicMask = uint.Parse(QueryResult["publicmask"].ToString());

                string challengeData = "";

                if (PlayerUniqueNick != null)
                {
                    PlayerEmail   = QueryResult["email"].ToString();
                    PlayerNick    = QueryResult["nick"].ToString();
                    challengeData = PlayerUniqueNick;
                }
                else if (PlayerAuthToken != null)
                {
                    PlayerEmail      = QueryResult["email"].ToString();
                    PlayerNick       = QueryResult["nick"].ToString();
                    PlayerUniqueNick = QueryResult["uniquenick"].ToString();
                    challengeData    = PlayerAuthToken;
                }
                else
                {
                    PlayerUniqueNick = QueryResult["uniquenick"].ToString();
                    challengeData    = Recv["user"];
                }

                // Use the GenerateProof method to compare with the "response" value. This validates the given password
                if (Recv["response"] == GenerateProof(Recv["challenge"], ServerChallengeKey, challengeData, PlayerAuthToken != null ? 0 : partnerID))
                {
                    // Create session key
                    SessionKey = Crc.ComputeChecksum(PlayerUniqueNick);

                    // Password is correct
                    Stream.SendAsync(
                        @"\lc\2\sesskey\{0}\proof\{1}\userid\{2}\profileid\{2}\uniquenick\{3}\lt\{4}__\id\1\final\",
                        SessionKey,
                        GenerateProof(ServerChallengeKey, Recv["challenge"], challengeData, PlayerAuthToken != null ? 0 : partnerID), // Do this again, Params are reversed!
                        PlayerId,
                        PlayerNick,
                        GameSpyLib.Random.GenerateRandomString(22, GameSpyLib.Random.StringType.Hex) // Generate LT whatever that is (some sort of random string, 22 chars long)
                        );

                    // Log Incoming Connections
                    LogWriter.Log.Write("Client Login:   {0} - {1} - {2}", LogLevel.Information, PlayerNick, PlayerId, RemoteEndPoint);

                    // Update status last, and call success login
                    LoginStatus          = LoginStatus.Completed;
                    PlayerStatus         = PlayerStatus.Online;
                    PlayerStatusString   = "Online";
                    PlayerStatusLocation = "";

                    CompletedLoginProcess = true;
                    OnSuccessfulLogin?.Invoke(this);
                    OnStatusChanged?.Invoke(this);

                    SendBuddies();
                }
                else
                {
                    // Log Incoming Connections
                    LogWriter.Log.Write("Failed Login Attempt: {0} - {1} - {2}", LogLevel.Information, PlayerNick, PlayerId, RemoteEndPoint);

                    // Password is incorrect with database value
                    Stream.SendAsync(@"\error\\err\260\fatal\\errmsg\The password provided is incorrect.\id\1\final\");
                    Disconnect(DisconnectReason.InvalidPassword);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Log.Write(ex.ToString(), LogLevel.Error);
                Disconnect(DisconnectReason.GeneralError);
                return;
            }
        }
Exemplo n.º 6
0
 private void OnSuccessfulLogin(OnSuccessfulLogin onSuccessfulLogin)
 {
     this._hasLoggedIn = true;
 }