Guest User

Guest User

  • Tech Writer
  • 20
  • 9.3k

how to change the value of a variable in a running program and save it for futute use

Jun 24 2012 8:26 AM
I want the user to be able to change his or her password after logging in to a Windows program and then save the new password for future sessions.

The code for the log in screen is:
public partial class Form1 : Form
    {
        Authenticator auth = new Authenticator();
       
        public Form1()
        {
            InitializeComponent();
           
        }

        private void btnLogIn_Click(object sender, EventArgs e)
        {
            string existingPassword = txtEnterPassword.Text;
            if (existingPassword == auth.Password)
            {
                MessageBox.Show("Password accepted. You may log in");
            }
            else
                MessageBox.Show("Password faild. Log in refused");
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            string existingPassword = txtEnterPassword.Text;
            string newPassword = txtChangePassword.Text;

            if (existingPassword == auth.Password)
            {
                auth.Password = newPassword;
                MessageBox.Show("Password changed. You may now use it to log in");
            }
            else
                MessageBox.Show("Password was not changed.");

        }

The code for the Authenticator class is:

public class Authenticator
    {
        private string password = "123Really";

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

Any helpful suggestions would be appreciated

Answers (3)