Click here to Skip to main content
16,013,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have four fields: old password, new password, confirm password and a change password button.

I want C# source code for changing password with respect to the database. Please help me out....
Posted
Comments
rbnsubedi01 28-Jun-11 2:01am    
my solution
.....................................

SqlConnection connect = new SqlConnection(str);
connect.Open();


string username = label_username.Text;
string password = textBox_Old.Text;
string newPassword = textBox_New.Text;
string confirmPassword = textBox_Verify.Text;
string sqlquery = "UPDATE [Member] SET Password=@newpass where Username=@username";
SqlCommand cmd = new SqlCommand(sqlquery, connect);
cmd.Parameters.AddWithValue("@newpass", textBox_Verify.Text);
cmd.Parameters.AddWithValue("@username", label_username.Text);
cmd.Parameters.AddWithValue("@password", textBox_Old.Text);

cmd.Connection = connect;

cmd.ExecuteNonQuery();

SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if ((textBox_New.Text == reader["newPassword"].ToString()) & (textBox_Verify.Text == (reader["confirmPassword"].ToString())))
{

}
}
MessageBox.Show("Password Changed Successfully!");
this.Close();
rbnsubedi01 28-Jun-11 2:03am    
when i click cancel bottom .. then blank password saves in the database..
please help me
Uday P.Singh 28-Jun-11 2:13am    
where is your cancel button code?
Uday P.Singh 28-Jun-11 2:05am    
what is your issue?

1 solution

So, your problem is where this code is, and why it's being run when it shouldn't be. The code will work fine, you just need to fix your event handling code so it only runs at the right time.
 
Share this answer
 
Comments
rbnsubedi01 28-Jun-11 5:53am    
please provide me a working code ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900