change password in database table using asp.net with C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raj200809
    New Member
    • Mar 2008
    • 4

    change password in database table using asp.net with C#

    Hi,

    I m trying update password in database using asp.net with c#.
    I have three text box in my aspx page
    Old password
    New password
    confirm password

    i m using following code but its not resolving

    step1 - this code in aspx.cs page
    [code=cpp]
    protected void btnchangepwd_Cl ick(object sender, EventArgs e)
    {
    try
    {
    if (IsValid)
    {

    SqlCommand cmd = new SqlCommand("HMS FetchPassword", con);
    cmd.CommandType = CommandType.Sto redProcedure;
    SqlDataReader dr;
    con.Open();
    cmd.Parameters. Add("@Pwd", this.txtoldpass .Text);
    dr = cmd.ExecuteRead er();
    if (dr.Read()==nul l)
    {
    if(txtoldpass.T ext==txtnewpass .Text)
    {
    cmd.CommandText ="HMSSP_UpdateP assword";
    cmd.CommandType =CommandType.St oredProcedure;
    cmd.Parameters. Add("@Pwd",this .txtoldpass.Tex t);
    // cmd.ExecuteNonQ uery();
    lblmessage.Visi ble=true;
    lblmessage.Text ="Your Password Sucessfully changed.";

    }
    else
    {
    lblmessage.Visi ble = true;
    lblmessage.Text = "Please enter correct Password ";
    }
    dr.Close();
    con.Close();
    }
    }
    }
    catch (Exception ex)
    {
    Response.Write( ex.Message);
    }
    }[/code]
    --------------------------------------------------------------------


    step-2
    [code=sql]
    CREATE procedure [dbo].[HMSSP_FetchPwd]
    (
    @Name varchar(200)
    )
    As
    SET NOCOUNT ON
    begin
    select Pwd from TblHMSOwner_Reg where Name=@Name
    End

    create procedure [dbo].[HMSSP_UpdatePas sword]
    (
    @Name Varchar(50),
    @Pwd Varchar(50)
    )
    As
    SET NOCOUNT ON
    begin
    update TblHMSOwner_Reg
    set Pwd=@Pwd where Name=@Name
    End[/code]




    hi if anyone have idea about it or have code then please help me
    thanks in advance
    Last edited by Frinavale; Apr 30 '08, 06:36 PM. Reason: added [code] tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You have:
    [code=cpp]
    if(txtoldpass.T ext==txtnewpass .Text)
    [/code]

    Don't you want to have?
    [code=cpp] if(txtnewpass.T ext==txtconfirm pass.Text)[/code]

    Then you have
    Code:
      cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
    But wouldn't you want to have?
    Code:
      cmd.Parameters.Add("@Pwd",this.txtnewpass.Text);
    Could you please explain what you are doing in your code?

    Thanks
    -Frinny

    Comment

    • raj200809
      New Member
      • Mar 2008
      • 4

      #3
      Originally posted by Frinavale
      You have:
      [code=cpp]
      if(txtoldpass.T ext==txtnewpass .Text)
      [/code]

      Don't you want to have?
      [code=cpp] if(txtnewpass.T ext==txtconfirm pass.Text)[/code]

      Then you have
      Code:
        cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
      But wouldn't you want to have?
      Code:
        cmd.Parameters.Add("@Pwd",this.txtnewpass.Text);
      Could you please explain what you are doing in your code?

      Thanks
      -Frinny
      Have you code change password

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by raj200809
        Have you code change password
        Every application will have a different way to change their password because their business rules will be different. Therefore, my code will not help you solve your problem.

        In your case you should check to see if both the Confirm Password and New Password fields match before attempting to add it to the database (you are not currently doing this in your code).

        You should also Update the user's password with the New Password if they do match (in your code you are currently updating the database with the Old Password...this is probably the main reason why your password is not updating...you' re replacing the old password with the old password...).

        -Frinny

        Comment

        • kunal pawar
          Contributor
          • Oct 2007
          • 297

          #5
          can u explain "HMSFetchPasswo rd" coz u list HMSSP_FetchPwd but wht abt "HMSFetchPasswo rd" store procedure and what it returns
          [code=cpp]
          //Please explain the following line
          SqlCommand cmd = new SqlCommand("HMS FetchPassword", con);
          cmd.CommandType = CommandType.Sto redProcedure;
          SqlDataReader dr;
          con.Open();
          cmd.Parameters. Add("@Pwd", this.txtoldpass .Text);
          dr = cmd.ExecuteRead er();
          if (dr.Read()==nul l)
          {
          if(txtoldpass.T ext==txtnewpass .Text)
          {
          cmd.CommandText ="HMSSP_UpdateP assword";
          cmd.CommandType =CommandType.St oredProcedure;
          cmd.Parameters. Add("@Pwd",this .txtoldpass.Tex t);
          // cmd.ExecuteNonQ uery();
          lblmessage.Visi ble=true;
          lblmessage.Text ="Your Password Sucessfully changed.";

          }
          else
          {
          lblmessage.Visi ble = true;
          lblmessage.Text = "Please enter correct Password ";
          }
          dr.Close();
          con.Close();
          }
          }
          }
          catch (Exception ex)
          {
          Response.Write( ex.Message);
          }
          }[/code]
          --------------------------------------------------------------------


          step-2
          [code=sql]
          CREATE procedure [dbo].[HMSSP_FetchPwd]
          (
          @Name varchar(200)
          )
          As
          SET NOCOUNT ON
          begin
          select Pwd from TblHMSOwner_Reg where Name=@Name
          End

          create procedure [dbo].[HMSSP_UpdatePas sword]
          (
          @Name Varchar(50),
          @Pwd Varchar(50)
          )
          As
          SET NOCOUNT ON
          begin
          update TblHMSOwner_Reg
          set Pwd=@Pwd where Name=@Name
          End[/code]

          Comment

          Working...