Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am developing a web app in visual studio using C# and sql server.
I want to create a page that the user should change his password.
i have tried this but no successs
pls help me find the error

C#
namespace Csharp
{
    public partial class change : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["new"] != null)
            {
                txt_username.Disabled = true;
                txt_username.Value = Session["username"].ToString();
            }
        }

       
        protected void btn_submit_Click(object sender, EventArgs e)
        {

            if (txt_newpass.Value.Length < 6)
            {
                Response.Write("<script language=Javascript>.....!</script>");
            }

            if (txt_newpass.Value != txt_newpass2.Value)
            {
                Response.Write("<script language=Javascript>......!</script>");
            }

           
            
            
            
            string pass;

            DataTable dt = new DataTable();
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringusersregj"].ConnectionString);
            conn.Open();

           
            string querysel = "Select * from Users where UserName='" + Session["username"].ToString() + "' ";
            SqlCommand kom = new SqlCommand(querysel, conn); 

            SqlDataAdapter sqlDa = new SqlDataAdapter(kom);

            sqlDa.Fill(dt);

            if(dt.Rows.Count>0)
            {
                pass = dt.Rows[0]["Password"].ToString();
                if (pass == txt_password.Value)
                {

                    string cod = "UPDATE Users set Password='"+ txt_newpass.Value +"' where UserName='" + Session["new"].ToString() + "'";
                    SqlCommand cmd = new SqlCommand(cod, conn);
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    Response.Write("<script language=Javascript>Old pass is incorredt</script>");
                }
            }
            conn.Close();
        }
    }
}
Posted
Comments
Abhishek Pant 29-Dec-12 5:39am    
http://www.asp.net/web-forms/tutorials/security/admin/recovering-and-changing-passwords-cs

1 solution

Before you even start to fix that, change the way you handle them!
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 

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