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

Programming Languages Ranking | Feb 2015 | JavaScript Greatest Performance

This is my second post along the blog speaking about programming languages ranking according to  TIOBE  for software quanlity. Before heading off to speak about the ranking, I would like to point out that this rank is based on the amount of searches and content availiable on the web for each programming language, You can read the full definition of TIOBE index  here .

5 Strategies to make money with Google AdSense

Hello geeks .. Before we start talking about those strategies you need to be sure that there's nothing called "Best Strategy" toward making money with  Google AdSense  as every one has his own experience and way of making money with this program and what may success with one person may fail with another person . So let us know some of those strategies for making money with AdSense Program .

Think Outside The Box

It was very much about not believing the traditional way of doing things. Don’t be afraid. Just because people tell you it can’t be done, that doesn’t necessarily mean that it can’t be done. It just means that they can’t do it. I think it’s always fun to think outside of the box and try to find new solutions to existing problems. I think simplicity is always a winner. If you can find a simpler solution to something—that has certainly for me been a guiding principle. Always try to make it simpler. I think to be really good at something, you have to be passionate about it too. That’s something you can’t learn. That’s just something that you have, I think. I got into programming not because I wanted to make lots of money or because someone told me to. I got into it because I just got totally absorbed by it. You just could not stop me. I had to write programs. It was the only thing I wanted to do. I was very, very passionate about it. You have to have that passion to get really good ...