コード例 #1
0
        /// <summary>
        /// Checks if edit password is ok text changed
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The event args</param>
        private void editPasswordBox_TextChanged(object sender, EventArgs e)
        {
            passwordOk = RegisterVerification.PasswordVertification(editPasswordBox.Text);

            if (editPasswordBox.Text != editPasswordBox.defaultText)
            {
                editPasswordBox.PasswordChar = '*';
            }
            else
            {
                editPasswordBox.PasswordChar = '\0';
            }

            if (passwordOk)
            {
                ChangeBackColorTextBox(editPasswordBox, true);
            }
            else
            {
                ChangeBackColorTextBox(editPasswordBox, false);
            }

            if (verifyEditPasswordBox.Text == editPasswordBox.Text)
            {
                ChangeBackColorTextBox(verifyEditPasswordBox, true);
                verifyPasswordOk = true;
            }
            else
            {
                ChangeBackColorTextBox(verifyEditPasswordBox, false);
                verifyPasswordOk = false;
            }

            if (editPasswordBox.Text == usernameBox.Text)
            {
                passwordStatusLabel.Text      = "Password can not be the same as your username";
                passwordStatusLabel.ForeColor = _wrongColor;
            }
            else
            {
                int strength = RegisterVerification.PasswordStrength(editPasswordBox.Text);

                if (strength == 0)
                {
                    passwordStatusLabel.Text = "";
                }
                else if (strength < 12)
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Weak", _wrongColor);
                }
                else if (strength < 22)
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Medium", Color.FromArgb(229, 200, 3));
                }
                else
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Strong", _correctColor);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Occurs when the text in the Password field is changed.
        /// Checks strength and validity of the password.
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The event args</param>
        private void registerPasswordBox_TextChanged(object sender, EventArgs e)
        {
            if (registerPasswordBox.Text != registerPasswordBox.defaultText)
            {
                registerPasswordBox.PasswordChar = '*';
            }
            else
            {
                registerPasswordBox.PasswordChar = '\0';
            }

            bool usernameNotSameAsPassword = registerPasswordBox.Text != registerUsernameBox.Text;
            bool verify = RegisterVerification.PasswordVertification(registerPasswordBox.Text) && usernameNotSameAsPassword;

            ChangeBackColorTextBox(registerPasswordBox, verify);
            _isPasswordOk = verify;

            VerifyPassword();

            if (!usernameNotSameAsPassword)
            {
                passwordStatusLabel.Text      = "Password can not be the same as your username";
                passwordStatusLabel.ForeColor = ColorScheme.MainWarningColor;
            }
            else
            {
                int strength = RegisterVerification.PasswordStrength(registerPasswordBox.Text);

                if (strength == 0)
                {
                    passwordStatusLabel.Text = "";
                }
                else if (strength < 12)
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Weak", ColorScheme.MainWarningColor);
                }
                else if (strength < 22)
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Medium", Color.FromArgb(229, 200, 3));
                }
                else
                {
                    ChangeLabelTextAndColor(passwordStatusLabel, "Strong", ColorScheme.MainThemeColorLight);
                }
            }
        }