コード例 #1
0
        private void textButtonOk_Click(object sender, EventArgs e)
        {
            try
            {
                _isOk = false;
                if (string.IsNullOrEmpty(textBoxInput.Text))
                {
                    MessageHelper.Popup(WinformRes.Input + ValidationRes.CanNotBeNull);
                    return;
                }

                if (VerificationRule.IsNullOrEmpty())
                {
                    _isOk = true;
                }
                else
                {
                    _isOk = GetHelper.VerifyPassword(textBoxInput.Text, VerificationRule, VerificationParams);
                }
                if (_isOk)
                {
                    _inputText = textBoxInput.Text;
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageHelper.Popup(ex.Message);
            }
        }
コード例 #2
0
        //#act
        internal bool VerifyStartPassword(bool verifyByInput, string passwordVerificationRule, string password)
        {
            try
            {
                if (!passwordVerificationRule.IsNullOrEmpty())
                {
                    if (passwordVerificationRule.Contains(";"))
                    {
                        passwordVerificationRule = passwordVerificationRule.Replace(";", ";");
                    }
                    if (passwordVerificationRule.Contains(","))
                    {
                        passwordVerificationRule = passwordVerificationRule.Replace(",", ",");
                    }
                    var verifyType   = passwordVerificationRule.SplitByTwoDifferentStrings("Type:", ";", true)[0];
                    var verifyParams = passwordVerificationRule.SplitByTwoDifferentStrings("Params:", ";", true)[0];

                    if (!EnumHelper.IsNameValid <PasswordEncryptionType>(verifyType))
                    {
                        throw new ArgumentException("passwordVerificationRule is not correct!");
                    }

                    if (verifyByInput)
                    {
                        StartPassword = verifyParams;
                        var dlg = new TextInputDialog();
                        {
                            dlg.Text               = EasyWinAppRes.PlsInputPassword;
                            dlg.VerificationRule   = verifyType;
                            dlg.VerificationParams = verifyParams;
                            dlg.ShowDialog();
                            return(dlg.IsOk);
                        }
                    }
                    else
                    {
                        if (GetHelper.VerifyPassword(password, verifyType, verifyParams))
                        {
                            StartPassword = verifyParams;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + GetType().FullName + ".VerifyStartPassword Error: " + ex.Message);
            }
            return(true);
        }
コード例 #3
0
        //# act
        internal bool VerifyStartPassword(bool verifyByInput, string passwordVerificationRule, string password)
        {
            if (!passwordVerificationRule.IsNullOrEmpty())
            {
                if (passwordVerificationRule.Contains(";"))
                {
                    passwordVerificationRule = passwordVerificationRule.Replace(";", ";");
                }
                if (passwordVerificationRule.Contains(","))
                {
                    passwordVerificationRule = passwordVerificationRule.Replace(",", ",");
                }

                var verifyTypeStr = passwordVerificationRule.SplitByTwoDifferentStrings("Type:", ";", true)[0];
                var verifyParams  = passwordVerificationRule.SplitByTwoDifferentStrings("Params:", ";", true)[0];

                if (!EnumHelper.IsNameValid <PasswordEncryptionType>(verifyTypeStr))
                {
                    throw new ArgumentException("passwordVerificationRule is not correct!");
                }
                if (verifyByInput)
                {
                    var i = 6;
                    do
                    {
                        Console.Write(EasyWinAppRes.PlsInputPassword + ": ");
                        var pass = Console.ReadLine();
                        if (GetHelper.VerifyPassword(pass, verifyTypeStr, verifyParams))
                        {
                            StartPassword = verifyParams;
                            return(true);
                        }
                        Console.WriteLine(string.Format(EasyWinAppRes.PasswordNotCorrectTryAgain, i - 1));
                        i--;
                    }while (i > 0);
                }
                else
                {
                    if (GetHelper.VerifyPassword(password, verifyTypeStr, verifyParams))
                    {
                        StartPassword = verifyParams;
                        return(true);
                    }
                }
            }
            return(false);
        }