Пример #1
0
        void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                _password = null;

                if (passwordTextBox.Text.Length == 0)
                {
                    DialogResult = DialogResult.None;

                    MessageBox.Show(this, "Password can't be empty.", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (passwordTextBox.Text != ConfirmPasswordTextBox.Text)
                {
                    DialogResult = DialogResult.None;

                    MessageBox.Show(this, "Password and confirm password don't match.", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    _password = UserAccessManager.GetSecureString(passwordTextBox.Text);

                    passwordTextBox.Text        = string.Empty;
                    ConfirmPasswordTextBox.Text = string.Empty;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, exception.Message, "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.DialogResult = DialogResult.None;

                if (userNamTextBox.Text.Length == 0)
                {
                    MessageBox.Show(this, "Enter a user name.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
                else if (passwordTextBox.Text.Length == 0)
                {
                    MessageBox.Show(this, "Enter a user password.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
                else if (!UserAccessManager.AuthenticateUser(userNamTextBox.Text, UserAccessManager.GetSecureString(passwordTextBox.Text)))
                {
                    MessageBox.Show(this, "Invalid user name or password.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
                else
                {
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                passwordTextBox.Text = string.Empty;
            }
        }