.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to make password change form?

Posted By: Manir     Posted Date: September 11, 2012    Points:5   Category :C#
Hi,
I would like to make form in visual c#.net which can change users password that is stored in sql 2005 table. I would also like to have function that will verify whether the "username",is correct or not and to verify the "new password" and "confirm password". appreciate your quick help!!!

Responses
Author: Manir             
Posted Date: September 12, 2012     Points: 20   

hi all

Do I still need to change to below code? as Im still getting
"The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined" error



private void btnChangePwd_Click(object sender, EventArgs e)
{

SqlConnection conn = new SqlConnection(@"Data Source=DMKWIN7MHADA\SQLEXPRESS;Initial Catalog=GymMaster;Integrated Security=True");
conn.Open();
string username = txtUserName.Text;
string password = txtPassword.Text;
string newPassword = txtNewPassword.Text;
string confirmPassword = txtConfirmNewPassword.Text;


//First check if you have the userName and password in databasestring

string sqlquery = "select count(username) from [tblusers] where Username=" + username;
//SqlCommand cmd = new SqlCommand(sqlquery, conn);
// string sqlquery = "select UserName,Password from [tblUsers] where UserName=@username and Password=@password";
SqlCommand cmd = new SqlCommand(sqlquery, conn);
SqlDataReader reader = new SqlDataReader();
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
reader = cmd.ExecuteReader();
reader.Read();
if (reader["UserName"].ToString() != String.Empty && reader["Password"].ToString() != String.Empty)
{
if (newPassword.Trim() != confirmPassword.Trim())
{
MessageBox.Show("New Password & confirm password doesnt match ");
clearAll();
if (newPassword.Trim() == confirmPassword.Trim())
{
sqlquery = "UPDATE [tblUsers] SET Password=@newpass where Username=@username";
cmd = new SqlCommand(sqlquery, conn);
cmd.Parameters.AddWithValue("@newpass", txtNewPassword.Text);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("Password Changed Successfully!");
}
}
}
else
{
MessageBox.Show("password not updated");
}
conn.Close();
this.Close();




Author: Manir             
Posted Date: September 12, 2012     Points: 20   

hi all

Do I still need to change to below code? as Im still getting
"The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined" error



private void btnChangePwd_Click(object sender, EventArgs e)
{

SqlConnection conn = new SqlConnection(@"Data Source=DMKWIN7MHADA\SQLEXPRESS;Initial Catalog=GymMaster;Integrated Security=True");
conn.Open();
string username = txtUserName.Text;
string password = txtPassword.Text;
string newPassword = txtNewPassword.Text;
string confirmPassword = txtConfirmNewPassword.Text;


//First check if you have the userName and password in databasestring

string sqlquery = "select count(username) from [tblusers] where Username=" + username;
//SqlCommand cmd = new SqlCommand(sqlquery, conn);
// string sqlquery = "select UserName,Password from [tblUsers] where UserName=@username and Password=@password";
SqlCommand cmd = new SqlCommand(sqlquery, conn);
SqlDataReader reader = new SqlDataReader();
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
reader = cmd.ExecuteReader();
reader.Read();
if (reader["UserName"].ToString() != String.Empty && reader["Password"].ToString() != String.Empty)
{
if (newPassword.Trim() != confirmPassword.Trim())
{
MessageBox.Show("New Password & confirm password doesnt match ");
clearAll();
if (newPassword.Trim() == confirmPassword.Trim())
{
sqlquery = "UPDATE [tblUsers] SET Password=@newpass where Username=@username";
cmd = new SqlCommand(sqlquery, conn);
cmd.Parameters.AddWithValue("@newpass", txtNewPassword.Text);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("Password Changed Successfully!");
}
}
}
else
{
MessageBox.Show("password not updated");
}
conn.Close();
this.Close();




Author: Manir             
Posted Date: September 12, 2012     Points: 20   

Hi all,

Thank you so much to all of your effort...the problem has been resolved...
below are the codes that i tried to resolved by using sqlhelper


public void clearAll()
{
txtUserName.Text = "";
txtPassword.Text = "";
txtNewPassword.Text = "";
txtConfirmNewPassword.Text = "";

}
private void btnChangePwd_Click(object sender, EventArgs e)
{
string username = txtUserName.Text;
string password = txtPassword.Text;
string newPassword = txtNewPassword.Text;
string confirmPassword = txtConfirmNewPassword.Text;

//First check if you have the userName and password in databasestring


if (txtNewPassword.Text == txtConfirmNewPassword.Text)
{
SQLHelper objSql = new SQLHelper();
objSql.SqlText = "select UserName,Password from [tblUsers] where UserName=@username and Password=@password ";
objSql.AddParameter("username", txtUserName.Text);
objSql.AddParameter("password", txtPassword.Text);

DataTable dt = objSql.getDataTable(false);

if (dt.Rows.Count == 1)
{
SQLHelper objSql1 = new SQLHelper();
objSql1.SqlText = "UPDATE [tblUsers] SET Password=@newpass where Username=@username";
objSql1.AddParameter("username", txtUserName.Text);
objSql1.AddParameter("newpass", txtNewPassword.Text);
objSql1.ExecuteScalar(false);
MessageBox.Show("Password successfully changed !!!");
//frmChangePassword changepwd = new frmChangePassword();
//changepwd.Close();
this.Close();
}
else
{
MessageBox.Show("Username or Old Password does not match");
clearAll();
}

}
else
{
MessageBox.Show("New and confirm Passwords do not match");
clearAll();
}
}
}




}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend