How to Change Password in asp.net website using C#

By
Hi Fiends ! Today ,I am going to explain "How to change password in asp.net website with example".If you are managing an asp.net website then you have to add this page on your website.It is simple and easy process. If you have built registration and login page on website then you have to add this page on your website, Because every registered users want to change your password for security purpose.if you add this page on your website then any registered user can easily change your password and secure your valuable data. 
   I have already built a registration and login page in our previous post.Some students wanted this change password page so i am going to add this page in our previous registration and login page. Now days ,Google ,Yahoo,Facebook ,Microsoft  and other websites are using this functionality for security purpose. 
I have build this page in separate post.you can add this page on your existing registration page by the copy and paste function.

There are some steps to implement this concepts on asp.net website as given below:-
Step 1 :-  First open your visual studio -->File -->New -->Select ASP.NET Empty website -->OK-->Open Solution Explore -->Add a New Web Form (login.aspx) -->Drag and Drop Label,Text Box ,Button ,SqlDataSource and validation control on the form from toolBox as shown below:-


login_form

Step 2 :- Now Open Your Solution Explorer --> Add a Database.mdf file -->create a table such  as cust_details with required column as shown below:-

table_data
Note:-Here you can take help for adding the .mdf database file on website.
Step 3 :- Now Right Click on Cust_details table --> Show Table Data -->You will see the all registered candidate's data as shown below:-


table_details

Step 4 :- Now configure SqlDataSource with table(cust_details)-->Click SqlDataSource --> Configure Data Source -->Select Database.mdf --> Next --> create My_ConnectionString---> Proceed with Next Button -->Finish-->done.

Step 5 :- Now write the following c# codes in login.aspx.cs page(login button click) as given below:-

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("select COUNT(*)FROM cust_details WHERE name='" + TextBox1.Text + "' and pass='" + TextBox2.Text + "'");
        cmd.Connection = con;
        int OBJ = Convert.ToInt32(cmd.ExecuteScalar());
        if (OBJ > 0)
        {
            Session["name"] = TextBox1.Text;
            Response.Redirect("Change_Password.aspx");
        }
        else
        {
            Label1.Text = "Invalid username or password";
        }
    }
}


Step 6 :- Now open Solution Explorer -->Add a New Web Form (change_password.aspx)  --> Drag and Drop Label,TextBox ,Button ,Required field validator  and Compare validator on the form as shown below:-


web_form

Note :-
Step 7 :- Now Write the all c# codes in change_password.aspx.cs page (Submit button click) as given below:-

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Change_Password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label2.Text = "Welcome " +Session["name"].ToString();
    }
         
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString);
        con.Open();
        string str1 = "select * from cust_details where pass ='" + TextBox1.Text + "'";
        SqlCommand cmd = new SqlCommand(str1, con);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
        SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString);
        con1.Open();
        string str = "update cust_details set pass='" +TextBox2.Text+ "'where pass= '"+TextBox1.Text+"'";
           SqlCommand cmd1 = new SqlCommand(str, con1);
          cmd1.ExecuteNonQuery(); 
          Label1.Text = "Your Password has been changed successfully ";
          con1.Close();
          con.Close();
        }
        else
        {
            Label1.Text = " Your old Password is incorrect try again... ";
        }
      
    }
}

Step 8 :- Run the Application (press F 5) -->Enter required loin deatails as shown below:--->Press Logon Button:-


web form

Step 9 :- Now Enter Required field details on change_password page -->press Submit Button as shown below:-



Note:-
  • Here user can't blank any Text Box Field.
  • Both New password field Should be same otherwise it will show an error message.
  • Old password should be correct otherwise you can not change the password.
Step 10 :- Now open Solution Explorer --> open Database.mdf file -->Right click on Cust_details -->Show Table data -->You will see that old password changed as shown below:-
database _value

Note:-
  • If your password have been changed then you can login in application with New Password without any problem. 
  • You can see your old password value in Step 3.
For More...
  1. How to build Form filling application like ibps website
  2. How to implement trigger concepts in sql server
  3. How to install ajax Toolkit in asp.net website with example
  4. How to save image in database and save in picture box control
  5. How to implement cookie concepts in asp.net website
  6. How to copy data from one table to another table easily
  7. How to implement join concepts in sql server
  8. How generate captcha image in new way in asp.net
  9. How to implement exception handling concepts in c#
  10. Difference between delete and truncate statement
  11. How to implement out parameter concepts in c#
  12. How to make ado.net real application
I hope this is helpful for you.
Please share this application if this helpful for you.

Download Whole Attached file 
       Download

11 comments:

  1. Thanks:- Ramshanker sir
    Realy this site is very helpful ............................

    ReplyDelete
  2. Sir..........
    I've a question. How to convert audio file to text file in windows application c# or VB 2010 Please explain step by step with code.
    Thanks and Regards Ram Jha

    ReplyDelete
    Replies
    1. Read below link:-
      http://www.codeproject.com/Articles/380027/Csharp-Speech-to-Text

      Delete
  3. all contains helpfull can u help me how convert vedio in audio...

    ReplyDelete
  4. Realy very usefull.. THANKS.

    ReplyDelete
  5. Sir i want to send confirmation code SMS in asp.net C# website how it can be done please replay my question

    ReplyDelete
  6. Sir i want to send confirmation code SMS in asp.net C# website how it can be done please replay my question

    ReplyDelete
  7. thanks man..... it really works... save me a lot of trouble...

    ReplyDelete
  8. very helpful.... thanks man... save me a lot of trouble...

    ReplyDelete

Powered by Blogger.