private void Login(Action action)
        {
            int            _loginCounter = 0;
            PasswordMasker masker        = new PasswordMasker();
            MainResult     result        = new MainResult();
            string         passCode      = "";

            do
            {
                passCode = masker.Mask($"Login (attempt: {_loginCounter}/5): ");
                if (String.IsNullOrEmpty(passCode) || passCode.Length <= 5)
                {
                    Write("Password length must be greater than 5 chars!");
                    ReadLine();
                    Clear();
                }
                else
                {
                    result = _iOSecurity.Login(passCode);
                    if (result.Success)
                    {
                        break;
                    }
                    else
                    {
                        Write($"Error: `{result.ErrorMessage}`");
                        ReadLine();
                        Clear();
                    }
                }
                _loginCounter++;
            } while (_loginCounter <= 5);
            if (result.Success)
            {
                action();
            }
            else if (_loginCounter == 5)
            {
                Environment.Exit(0);
            }
        }
        private void ChangePassword(Action action)
        {
            PasswordMasker masker = new PasswordMasker();
            string         key    = "";

            do
            {
                key = masker.Mask("Set password (length>5): ");
                if (String.IsNullOrEmpty(key) || key.Length <= 5)
                {
                    Write("Password length must be greater than 5 chars!");
                    ReadLine();
                    Clear();
                }
                else if (File.Exists(Global.MasterKeyLocation) && _iOSecurity.Login(key).Success)
                {
                    Write("You cannot input the same password!");
                    ReadLine();
                    Clear();
                }
                else
                {
                    break;
                }
            } while (true);
            WriteLine("Loading...");
            MainResult result = _iOSecurity.ChangeMasterKey(key);

            if (result.Success)
            {
                WriteLine("Password changed successfully");
            }
            else
            {
                WriteLine($"Error: `{result.ErrorMessage}`");
            }
            action();
        }
예제 #3
0
 public string ReadPassword()
 {
     return(PasswordMasker.ReadPasswordFromConsole());
 }