Skip to main content

How To Create A Change Password Form in a C# Application

Hello Geeks .. This little post is a free sample C# Windows Form that can be used to change password in a SQL Database .

In this Sample you will find a class called ChangeInDB.cs and Other Called Connection.cs I use those two classes in the process of connecting to Database.Open Them and Change the Connection String to be the One for your own computer .

Link To Download The Working Sample : Change Password Win Form

Steps To Implement Change Password Form Inside your Applications : 

  1. Create a SQL Database Table That has UserID and Password Fields and Add Some Records.
  2. Create a class to implement connections to Database and methods of communicating with your Database . 

  3. Add Those Methods Inside It
    public DataTable RunQuery(string select)
    {
         SetComnd(select);
         myTable.Load(cmd.ExecuteReader());
         return myTable;
    }
    public bool login(string user, string pass)
    {
         connect();
         string sqlcmd = "select * from LoginInfo where ID='" + user + "' and Password='" + pass + "'";
         DataTable mytbl = RunQuery(sqlcmd);
         if (mytbl.Rows.Count > 0) return true;
         else return false;
    }
    private void connect()
    { cn.Open(); }

  4. Implement This Code Under The ButtonConfirm_Click Event
    private void btnConfirm_Click(object sender, EventArgs e)
    {
         SqlCommand cmd = new SqlCommand();
         SqlConnection cn = new SqlConnection(Connection.myConnectionString);
         ChangeInDB changePass = new ChangeInDB();
         string strCmd ="update LoginInfo set Password='"+txtNew.Text+"' where ID='"+txtUser.Text+"'";
         if (changePass.login(txtUser.Text, txtOld.Text) == true)
         {
              if (txtNew.Text == txtVerify.Text)
              {
                 try
                {
                  cn.Open();
                  cmd.Connection = cn;
                  cmd.CommandText = strCmd;
                  cmd.ExecuteNonQuery();
                  MessageBox.Show("Done Successfully!");
                }
                catch (Exception ex)
                {
                   MessageBox.Show(ex.ToString());
                }
             }
       else
          MessageBox.Show("Passwords Does Not Match");
        }
     else
      MessageBox.Show("User/Password Incorrect!");
    }

  5. Add The Features you want in your form such as minimum & maximun set of chars for password  ... Etc .

You May Also Read :

Comments

Popular posts from this blog

C# Full Pharmacy Project With Source code

Hello Geeks .. This post is one of our completely Free Projects  .. It is a Pharmacy Project that can perform a lot of operations you can also find the (.dll) files for the working Barcode Reader Machines in your country and add it to the project .

Microsoft Interview - MSP Windows 8 Vertical

Hello Geeks ..It seems to be my return to posting starting today , and i will start by telling about the Interview i just had in Microsoft for MSP - Club . You first need to know that questions are both technical and social , they need to know the real you , weather you understand what you are saying or not , weather you know your limits and able to control it or not . I applied for Microsoft Windows 8 vertical  to be a Microsoft Partner Presenter in my college . MSP Club - Windows 8 Vertical