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

How To Create C# Chat Application

Hello Geeks .. Today I gonna show you How to make a Chat Application Using Microsoft C#.NET 5.0  . You Can Use Older Versions Since there is nothing special in the application that only belongs to C# 5.0 . This Application Was Created To Allow Two Computers To "Chat" Using IP Addresses Also you Can Open two Clients On The Same Computer and Use Same IP Address But Different Port.. It is simple and Easy to Use And Develop .. I also Uploaded The Full Working Project With It's Source Code On MediaFire.. You Will Find The Link At The End Of the Post :)

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 .