Exemple #1
0
        private void buttonAdd_Click(object sender, System.EventArgs e)
        {
            TextBoxForm form = null;
            string      username;

            try
            {
                form         = new TextBoxForm();
                form.Text    = "Enter Username";
                form.Caption = "Enter username:"******"User already exists.");
                    return;
                }
            }
            finally
            {
                if (form != null)
                {
                    form.Dispose();
                }
            }

            try
            {
                form         = new TextBoxForm();
                form.Text    = "Enter password";
                form.Caption = "Enter password for " + username + ":";
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                string password = form.TextBox.Text;

                authenticator.AddUser(username, password);
                userList.Items.Add(username);
                userList.SelectedItem = username;
            }
            finally
            {
                if (form != null)
                {
                    form.Dispose();
                }
            }
        }
Exemple #2
0
        private void buttonPassword_Click(object sender, System.EventArgs e)
        {
            if (userList.SelectedIndex < 0)
            {
                return;
            }

            string user = userList.SelectedItem as string;
            string currentPass;
            string newPass;

            TextBoxForm form = null;

            try
            {
                form         = new TextBoxForm();
                form.Text    = "Enter current password";
                form.Caption = "Enter current password for user " + user + ":";
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                currentPass = form.TextBox.Text;
            }
            finally
            {
                if (form != null)
                {
                    form.Dispose();
                }
            }

            try
            {
                form         = new TextBoxForm();
                form.Text    = "Enter new password:"******"Enter new password for user " + user + ":";
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                newPass = form.TextBox.Text;
            }
            finally
            {
                if (form != null)
                {
                    form.Dispose();
                }
            }

            try
            {
                authenticator.ChangePassword(user, currentPass, newPass);
            }
            catch (System.Security.SecurityException)
            {
                MessageBox.Show(this, "Password is incorrect.");
            }
        }