Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
This is my .aspx code. I have three textboxes and one submit button
1-Current Password
2-New Password
3-Confirm password

ASP.NET
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        <table class="style1">
            <tr>
                <td class="style2">
                    Current Password</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <asp:HyperLink ID="HyperLink1" runat="server" 
                        NavigateUrl="~/ForgotPassUser.aspx">Forgot Password ?</asp:HyperLink>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    New Password</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Confirm New Password</td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                     </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Save Settings" />
                </td>
            </tr>
        </table>
    
    </div>
    </form>
</body> 
Posted
Comments
[no name] 10-Mar-14 1:50am    
Hi...
Enter Current, new and confirm Password in ur textboxes. 1st check current password existed in db and compare new, confirm passwords. After that only update db with new password use condition.
Thank u.
jayraj86 10-Mar-14 2:03am    
can you write that code ?

Hi,
Please write the bellow function "ChangePassword()" under Button1 click

This will work for the changing password.If any error comes please let me know.

C#
private void ChangePassword()
    {
        try
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from tbllogin wherere username='" + txtUsername.Text + "'", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            con.Close();
            string username=ds.Tables[0].Rows[0][1].ToString();
            string OLdpassword=ds.Tables[0].Rows[0][2].ToString();
            if (OLdpassword == txtOLDPassword.Text)
            {
                if (txtNewPassword.Text == txtConfirmPassword.Text)
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("update tbllogin set password='" + txtNewPassword.Text + "' where username='" + txtUsername.Text + "'");
                    int querystatus = cmd.ExecuteNonQuery();
                    if (querystatus > 0)
                    {
                        lblError.ForeColor = System.Drawing.Color.Green;
                        lblError.Text = "Password updated successfully";
                    }
                    else
                    {
                        lblError.ForeColor = System.Drawing.Color.Red;
                        lblError.Text = "Execution error";
                    }
                }
                else
                {
                    lblError.ForeColor = System.Drawing.Color.Red;
                    lblError.Text = "Password miss match";
                }
            }
            else
            {
                lblError.ForeColor = System.Drawing.Color.Red;
                lblError.Text = "Old password is incorrect";
            }
        }
        catch { }
        finally { con.Close(); }
    }
 
Share this answer
 
v2
Comments
jayraj86 10-Mar-14 4:29am    
error in second last line on con.close();

'the name 'con' does not exist in current context'
SanSkun 10-Mar-14 6:23am    
I think u have not created the connection class.So create connection class with connection string.
SqlConnection con=new SqlConnection("Your databaseconnevtion string");
Add this publicly,then all code will work without any error.
Member 12504501 30-May-16 16:43pm    
where is the form of this code aspx file ???
Hai

If u want to change password as ur design,just get 3 text box values,first check with current password with db and then compare new pass and confirm pass and then update in user table.

If u want to reset password,u need to get new password and user email address,check email address is correct or not with db,and update new password in db and also send new pass word via mail,bca u have user email address.

The above 2 way u can use,all are easy ,just select query ,compare values and update values,in ur project u use all queries why u need codings,just use ur exesting query and chnage little bit.

try this link
select update insert delete commands in c# asp.net[^]

Regards
Aravind
 
Share this answer
 
Here we answer specific questions which members face during programming.

We can't work on the whole source code. You need to do that yourself.
If you face any difficulty while coding, feel free to come back here and ask another question with specific issue describing the scenario.

Members will be happy to help you then.

Happy Coding. :)
 
Share this answer
 
Comments
VICK 10-Mar-14 4:11am    
M confused to see "this advice" from a senior member as a SOlution.. :O
Can't it be posted as a comment to OP???
Yeah, but sometimes, comment don't work. When we post this as a comment, others who come to this thread don't bother to see the comment and add another answer. When we add this as an answer, the person seeing the question next does not add an answer; simple ignores it. That is the goal.
VICK 10-Mar-14 4:31am    
Good Logic... Confusion Flown.. :D

:) Thanks. :)
Member 10584788 11-Mar-14 2:52am    
this is the simplest change password code.....i had never seen before.....great job!!!!!!!!

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