Ejemplo n.º 1
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;
            }
        }