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 .
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 :
- Create a SQL Database Table That has UserID and Password Fields and Add Some Records.
- Create a class to implement connections to Database and methods of communicating with your Database .
- 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(); } - 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!");
} - Add The Features you want in your form such as minimum & maximun set of chars for password ... Etc .
Comments
Post a Comment
We Care About Your Opinion !