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

                if (VerificationRule.IsNullOrEmpty())
                {
                    _isOk = true;
                }
                else
                {
                    _isOk = TextVerificationHelper.Verify(textBoxInput.Text, VerificationRule, VerificationParams);
                }
                if (_isOk)
                {
                    _inputText = textBoxInput.Text;
                    Close();
                }
            }
            catch (Exception ex)
            {
                PopupMessage.Popup(ex.Message);
            }
        }
コード例 #2
0
        internal static bool VerifyPassword(string passwordVerificationStr, string password)
        {
            try
            {
                if (!passwordVerificationStr.IsNullOrEmpty())
                {
                    //passwordVerificationStr = EncryptionHelper.SmDecrypt(passwordVerificationStr,
                    //                          StartHelper.GlobalEncrptKey1, StartHelper.GlobalEncrptKey2);
                    if (passwordVerificationStr.Contains(";"))
                    {
                        passwordVerificationStr = passwordVerificationStr.Replace(";", ";");
                    }
                    if (passwordVerificationStr.Contains(","))
                    {
                        passwordVerificationStr = passwordVerificationStr.Replace(",", ",");
                    }
                    var accessType   = passwordVerificationStr.SplitByTwoDifferentStrings("AccessType:", ";", true)[0];
                    var verifyRule   = passwordVerificationStr.SplitByTwoDifferentStrings("VerificationRule:", ";", true)[0];
                    var verifyParams = passwordVerificationStr.SplitByTwoDifferentStrings("VerificationParams:", ";", true)[0];

                    if (verifyRule.ToLower() != "ClearText".ToLower() & verifyRule.ToLower() != "TdePassword".ToLower() & verifyRule.ToLower() != "Password".ToLower())
                    {
                        throw new ArgumentException("verifyRule is not correct!");
                    }

                    if (accessType.ToLower() == "Manual".ToLower())
                    {
                        var dlg = new TextInputDialog();
                        {
                            dlg.Text               = EasyWinAppRes.PlsInputPassword;
                            dlg.VerificationRule   = verifyRule;
                            dlg.VerificationParams = verifyParams;
                            dlg.ShowDialog();
                            return(dlg.IsOk);
                        }
                    }
                    else if (accessType.ToLower() == "Auto".ToLower())
                    {
                        if (password.IsNullOrEmpty())
                        {
                            throw new ArgumentException("Password can't be empty!");
                        }
                        else
                        {
                            if (!TextVerificationHelper.Verify(password, verifyRule, verifyParams))
                            {
                                throw new ArgumentException("Password is incorrect!");
                            }
                        }
                    }
                    else if (accessType.ToLower() == "Both".ToLower())
                    {
                        if (password.IsNullOrEmpty())
                        {
                            var dlg = new TextInputDialog();
                            {
                                dlg.Text               = EasyWinAppRes.PlsInputPassword;
                                dlg.VerificationRule   = verifyRule;
                                dlg.VerificationParams = verifyParams;
                                dlg.ShowDialog();
                                return(dlg.IsOk);
                            }
                        }
                        else
                        {
                            if (!TextVerificationHelper.Verify(password, verifyRule, verifyParams))
                            {
                                throw new ArgumentException("Password is incorrect!");
                            }
                        }
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".CheckStartPassword Error: " + ex.Message);
            }
            return(true);
        }