473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. protected void btnchangepwd_Click(object sender, EventArgs e)
  2.     {
  3.         try
  4.         {
  5.             if (IsValid)
  6.             {
  7.  
  8.                 SqlCommand cmd = new SqlCommand("HMSFetchPassword", con);
  9.                 cmd.CommandType = CommandType.StoredProcedure;
  10.                 SqlDataReader dr;
  11.                 con.Open();
  12.                 cmd.Parameters.Add("@Pwd", this.txtoldpass.Text);
  13.                 dr = cmd.ExecuteReader();
  14.                 if (dr.Read()==null)
  15.                 {
  16.                     if(txtoldpass.Text==txtnewpass.Text)
  17.                     {
  18.                         cmd.CommandText="HMSSP_UpdatePassword";
  19.                         cmd.CommandType=CommandType.StoredProcedure;
  20.                         cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
  21.                        // cmd.ExecuteNonQuery();
  22.                        lblmessage.Visible=true;
  23.                        lblmessage.Text="Your Password Sucessfully changed.";
  24.  
  25.                     }
  26.                     else
  27.                     {
  28.                    lblmessage.Visible = true;
  29.                    lblmessage.Text = "Please enter correct Password ";
  30.                     }
  31.                 dr.Close();
  32.                 con.Close();
  33.             }
  34.         }
  35.       }
  36.         catch (Exception ex)
  37.         {
  38.             Response.Write(ex.Message);
  39.         }
  40.     }
--------------------------------------------------------------------


step-2
Expand|Select|Wrap|Line Numbers
  1. CREATE procedure [dbo].[HMSSP_FetchPwd]
  2. (
  3. @Name varchar(200)
  4. )
  5. As
  6. SET NOCOUNT ON
  7. begin
  8. select Pwd from TblHMSOwner_Reg where Name=@Name
  9. End
  10.  
  11. create procedure [dbo].[HMSSP_UpdatePassword]
  12. (
  13. @Name Varchar(50),
  14. @Pwd Varchar(50)
  15. )
  16. As
  17. SET NOCOUNT ON
  18. begin
  19. update  TblHMSOwner_Reg
  20. set Pwd=@Pwd where Name=@Name
  21. End



hi if anyone have idea about it or have code then please help me
thanks in advance
Apr 30 '08 #1
4 22692
Frinavale
9,735 Expert Mod 8TB
You have:
Expand|Select|Wrap|Line Numbers
  1.   if(txtoldpass.Text==txtnewpass.Text)
  2.  
Don't you want to have?
Expand|Select|Wrap|Line Numbers
  1.   if(txtnewpass.Text==txtconfirmpass.Text)
Then you have
Expand|Select|Wrap|Line Numbers
  1.   cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
But wouldn't you want to have?
Expand|Select|Wrap|Line Numbers
  1.   cmd.Parameters.Add("@Pwd",this.txtnewpass.Text);
Could you please explain what you are doing in your code?

Thanks
-Frinny
Apr 30 '08 #2
You have:
Expand|Select|Wrap|Line Numbers
  1.   if(txtoldpass.Text==txtnewpass.Text)
  2.  
Don't you want to have?
Expand|Select|Wrap|Line Numbers
  1.   if(txtnewpass.Text==txtconfirmpass.Text)
Then you have
Expand|Select|Wrap|Line Numbers
  1.   cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
But wouldn't you want to have?
Expand|Select|Wrap|Line Numbers
  1.   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
May 1 '08 #3
Frinavale
9,735 Expert Mod 8TB
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
May 1 '08 #4
kunal pawar
297 100+
can u explain "HMSFetchPassword" coz u list HMSSP_FetchPwd but wht abt "HMSFetchPassword" store procedure and what it returns
Expand|Select|Wrap|Line Numbers
  1.               //Please explain the following line
  2.               SqlCommand cmd = new SqlCommand("HMSFetchPassword", con);
  3.                 cmd.CommandType = CommandType.StoredProcedure;
  4.                 SqlDataReader dr;
  5.                 con.Open();
  6.                 cmd.Parameters.Add("@Pwd", this.txtoldpass.Text);
  7.                 dr = cmd.ExecuteReader();
  8.                 if (dr.Read()==null)
  9.                 {
  10.                     if(txtoldpass.Text==txtnewpass.Text)
  11.                     {
  12.                         cmd.CommandText="HMSSP_UpdatePassword";
  13.                         cmd.CommandType=CommandType.StoredProcedure;
  14.                         cmd.Parameters.Add("@Pwd",this.txtoldpass.Text);
  15.                        // cmd.ExecuteNonQuery();
  16.                        lblmessage.Visible=true;
  17.                        lblmessage.Text="Your Password Sucessfully changed.";
  18.  
  19.                     }
  20.                     else
  21.                     {
  22.                    lblmessage.Visible = true;
  23.                    lblmessage.Text = "Please enter correct Password ";
  24.                     }
  25.                 dr.Close();
  26.                 con.Close();
  27.             }
  28.         }
  29.       }
  30.         catch (Exception ex)
  31.         {
  32.             Response.Write(ex.Message);
  33.         }
  34.     }
--------------------------------------------------------------------


step-2
Expand|Select|Wrap|Line Numbers
  1. CREATE procedure [dbo].[HMSSP_FetchPwd]
  2. (
  3. @Name varchar(200)
  4. )
  5. As
  6. SET NOCOUNT ON
  7. begin
  8. select Pwd from TblHMSOwner_Reg where Name=@Name
  9. End
  10.  
  11. create procedure [dbo].[HMSSP_UpdatePassword]
  12. (
  13. @Name Varchar(50),
  14. @Pwd Varchar(50)
  15. )
  16. As
  17. SET NOCOUNT ON
  18. begin
  19. update  TblHMSOwner_Reg
  20. set Pwd=@Pwd where Name=@Name
  21. End
May 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: David | last post by:
Hi, Could someone please xplain how to add a field to an existing SQL table in VB.Net I have added the field in the Server Explorer and it shows up when I reload the program but I cannot...
4
by: Rnt6872 | last post by:
I need to import a .csv file into a firebird database. I am able to cnnect tothe databe using: Dim ds1 As New DataSet Dim SQLString As String = "insert into rdstype27...
0
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
4
by: qwedster | last post by:
Howdy folks! I am using stored procedure to see if a value exists in database table and return 0 if exists or else -1, in the following SQL queries. However how to check if a value (that is...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
11
by: sshade25 | last post by:
I am trying to insert some data into my postgresql database table using an html form and a php script. The problem here is that when the script is run, it does not insert data into the last two...
5
by: asmi | last post by:
I am new in C# programming. Can anyone plz help me in the following problem. I am changing values in different columns in access database table using c# but these changes are only visible at run...
2
JnrJnr
by: JnrJnr | last post by:
I have two SQL database tables. One contains various products(with unique primary keys) and the other contains information related to the products aswel as the product's foreign keys. What I want...
3
by: btreddy | last post by:
Hii.., I've a form where some 10 textboxes are there with lables along with them.i need to add the lable text and textbox text as a single row to database table.so i've 20 text boxes and 20...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.