Question Change password for user

Dreal1

Member
Joined
Apr 27, 2017
Messages
10
Programming Experience
Beginner
I HAVE BEEN WORKING ON THIS CHANGE OF PASSWORD CODE FOR A WHILE NOW AND IT HAS BEEN GIVEN ME ALOT OFF ISSUES.
CAN SOMEONE PLEASE HELP ME OUT , PLEASE CHECK THE CODE BELOW.


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Changepassword : System.Web.UI.Page
{
CRMDataClassesDataContext db = new CRMDataClassesDataContext();
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
byte up;
protected void btn_update_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from Login ";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
if (txt_cpassword.Text == reader["PasswordX"].ToString())
{
up = 1;
}
}
reader.Close();
con.Close();
if (up == 1)
{
con.Open();
str = "update login set Password=@Password where UserName='" + Session["UserName"].ToString()+ "'";
com = new SqlCommand(str, con);
com.Parameters.Add(new SqlParameter("@PasswordX", SqlDbType.VarChar, 50));
com.Parameters["@PasswordX"].Value = newpasstxt.Text;
com.ExecuteNonQuery();
con.Close();
MessageLabel.Text = "Password changed Successfully";
}
else
{
MessageLabel.Text = "Please enter correct Current password";
}
}
}
 
THANKS.
 
Welcome. Firstly, any time a code snippet is posted without indenting, it becomes harder to read. Please post your code snippets as plain text, i.e. no HTML formatting or the like, inside appropriate code formatting tags, e.g.

[xcode=c#]your code here[/xcode]

As for the problem, you haven't actually described it. It's not really enough to say "here's my code, fix it". You should be providing a FULL and CLEAR explanation of the issue, which means describing what the code is supposed to do and EXACTLY how what it actually does differs from that. If there's an error message then provide it and exactly where in the code it's generated.

If there isn't an error message but the behaviour is wrong then describe that and EXACTLY where it happens. If you don't know exactly where it happens then you need to do some debugging. That means setting a breakpoint at the top of the code and stepping through it to see exactly what path execution takes and also checking the values of your variables and the like at each step to see if an when they contain the wrong values.
 
Back
Top Bottom