Introduction: Hello friends, in this article i will explain that how we
can change the password after login, in asp.net.This article is very useful for
the all the .net developer.
Implementation: create a new website add a page. Drag and drop three
textboxes and two buttons from the
toolbox inside the <body> body
tag at the .aspx page. Below i am giving the complete code for the html
page and .cs page.
Code for default.aspx page
<div>
<table style="width: 91%; height: 97px;" class="tbl_reg_form">
<tr>
<td>
Old Password</td>
<td>
<asp:TextBox ID="txt_old_pwd" runat="server" CssClass="input" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txt_old_pwd" ErrorMessage="Required">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
New Password</td>
<td>
<asp:TextBox ID="txt_new_pwd" runat="server" CssClass="input" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txt_new_pwd" ErrorMessage="Required">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="height: 29px">
Confirm Password</td>
<td style="height: 29px">
<asp:TextBox ID="txt_confirm_pwd" runat="server" CssClass="input" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txt_confirm_pwd" ErrorMessage="Required">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txt_new_pwd" ControlToValidate="txt_confirm_pwd"
ErrorMessage="CompareValidator">New
Password does not match</asp:CompareValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btn_submit" runat="server"
Text="Change Password" onclick="btn_submit_Click" />
<asp:Button ID="btn_cancel"
runat="server"
CausesValidation="False"
Text="Reset" onclick="btn_cancel_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lbl_msg" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
Code for default.aspx.cs page
using System;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
System.Data.SqlClient;
using
System.Drawing;
public partial class _Default : System.Web.UI.Page
{
SqlCommand
cmd;
DataTable
dt;
SqlConnection
con = new SqlConnection();
SqlDataAdapter
adp;
protected void Page_Load(object
sender, EventArgs e)
{
// here i am
declare connection
con = new
SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
con.Open();
if
(con.State == ConnectionState.Closed)
{
con.Open();
}
}
protected void btn_submit_Click(object
sender, EventArgs e)
{
if
(con.State == ConnectionState.Closed)
{ con.Open(); }
try
{
// here
inside the cmd definning sql query to
select the password from the table
adp = new
SqlDataAdapter("select
password from REGISTRATION where
password=?password and username=?username", con);
//
Passing parameters
adp.SelectCommand.Parameters.AddWithValue("?password",
txt_old_pwd.Text);
// This program will be working when the user
will login inside the application so you can pass parameter
// named
username via session or cokkie, here i am using session
adp.SelectCommand.Parameters.AddWithValue("?username",
Session["username"].ToString());
dt = new
DataTable();
adp.Fill(dt);
// Here
checked the enter old password is available inside the database or no
// If the
old password not correct entered by the user, then it will enter inside the if
condition
if
(dt.Rows.Count == 0)
{
// it
will display message inside the lable
lbl_msg.ForeColor = Color.Red;
lbl_msg.Text = "Old Password does not match";
clr_rec();
return;
}
// If the
old password correct entered by the
user, then it will enter inside the else condition
else
{
//
here inside the cmd definning sql query
to update the password from the table
cmd = new SqlCommand("update
REGISTRATION set password=?password where
username=?username", con);
//
Passing parameters
cmd.Parameters.AddWithValue("?password", txt_new_pwd.Text);
// This program will be working when the user
will login inside the application so you can pass parameter
//
named username via session or cokkie, here i am using session.
cmd.Parameters.AddWithValue("?username", Session["username"].ToString());
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
// it
will display message inside the lable that password has changed Successfully
lbl_msg.Text = "Password has changed Successfully";
clr_rec();
}
}
catch {
}
}
protected void btn_cancel_Click(object
sender, EventArgs e)
{
clr_rec();
}
private void clr_rec()
{
// this
method will crear all the mentioned textboxes.
txt_confirm_pwd.Text = "";
txt_new_pwd.Text = "";
txt_old_pwd.Text = "";
}
}
Connectionstring
<connectionStrings>
<add
name="cnn" connectionString="Data
source=BHARAT-HP;database=practice;uid=sa;pwd=1234;Min Pool Size=100;Max Pool
Size=1000;Connect Timeout=10"/>
</connectionStrings>
Database Script
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[REGISTRATION]')
AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[REGISTRATION](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[username] [varchar](50) NULL,
[password] [varchar](50) NULL,
CONSTRAINT
[PK_REGISTRATION] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS
= ON, ALLOW_PAGE_LOCKS
= ON) ON [PRIMARY]
) ON [PRIMARY]
END
See the output inside the image below
Conclusion: In above code, I have been explained that
how we can change password in asp.net. This code is very helpful for
every .net developer. Gud bye and take care developers. We will come back
shortly with the new article.
Regards
Using Asp.net
Great !
ReplyDeleteASP.Net training
Aws online training in india
ReplyDeleteSalesforce online training in india
SAS Online Training in india
Salesforce admin online training in india
Linux Online
training in India
Digital Marketing Online Training in India
ReplyDeleteCloud Computing Online Training in India
Hadoop online training in INDIA
Javascript Training In Noida
Industrial Training in Noida
This comment has been removed by the author.
ReplyDeletehealthkart deals and offers
ReplyDeletehealthkart discount offers
bigbasket promo codes
bigbasket coupon codes
bigbasket offers
bigbasket coupon and deals
pizzahut promo code
pizzahut coupon codes
pizzahut offers
pizzahut coupon and offers
hotels promo code
hotels coupon codes
hotel offers & deals
hotels discount offers
nearbuy coupon codes
nearbuy promo codes
nearbuy deals and offers
nearbuy discounts
zoomcar promo code
zoomcar coupon code
zoomcar offers on ride
zoomcar deals and offers
Cloud Computing Training In Noida
ReplyDeleteWebtrackker is IT based company in many countries. Webtrackker will provide you a real time projects based training on Cloud Computing. If you are looking for the Cloud computing training in Noida then you can join the webtrackker technology.
Cloud Computing Training In Noida , Cloud Computing Training center In Noida , Cloud Computing Training institute In Noida ,
Company Address:
Webtrackker Technology
C- 67, Sector- 63, Noida
Email: info@webtrackker.com
Website: www.webtrackker.com
http://webtrackker.com/Cloud-Computing-Training-Institutes-In-Noida.php
Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.
ReplyDeleterpa Training in Chennai
rpa Training in bangalore
rpa Training in pune
blueprism Training in Chennai
blueprism Training in bangalore
blueprism Training in pune
iot-training-in-chennai
Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Roles and reponsibilities of hadoop developer | hadoop developer skills Set | hadoop training course fees in chennai | Hadoop Training in Chennai Omr
ReplyDeleteWOW! Really Nice Post! I personally believe that to maintain the standard of a blog all the hacks mentioned above are important. All points discussed were worth reading
ReplyDeleteand I’ll surely work with them all one by one.
CEH Training In Hyderbad
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteLinux Training in Chennai
Python Training in Chennai
Data Science Training in Chennai
RPA Training in Chennai
Devops Training in Chennai
This blog is full of Innovative ideas.surely i will look into this insight.please add more information's like this soon.
ReplyDeleteHadoop Training in Chennai
Big data training in chennai
Big Data Course in Chennai
JAVA Training in Chennai
Python Training in Chennai
Selenium Training in Chennai
Hadoop training in chennai
Big data training in chennai
hadoop training in Velachery
Are you looking for Distance Learning Courses in India most of the students choose and apply, Talentedgenex there are many popular courses which attract the students for having distance education. For more info visit this site:- Distance learning courses in India ,
ReplyDeleteTalentedgenext Way of Online Learning, Distance Education, is an increasing number of becoming popular all over the world due as it has many benefits. For further details visit in this site:- Distance Education Website,
ReplyDeleteOnline BBA degree in India is one of the most popular couses for students who are keen to learn business statistics, communicating skills, marketing management, entrepreneurship and small business management, international business, etc. To know more, visit:
ReplyDeleteOnline BBA Degree in India,
ReplyDeleteNice blog! i'm also working with a graphic designing services in gurgaon.
Freelance Graphic Designing
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
Freelance Catalogue Designing in delhi
Freelance Catalogue Designing in gurgaon
Freelance Brochure Designing
Freelance Label Designing
Freelance Banner Designer
Freelance Poster Designer
graphic design services in delhi
graphic design services in gurgaon
graphic designer in gurgaon
freelance graphic designer in gurgaon
freelance graphic designer in gurgaon
freelance graphic designer in gurgaon
freelance logo designer in gurgaon
freelance logo designer in gurgaon
freelance web designer in gurgaon
Awesome post...
ReplyDeleteinternship report on python
free internship in chennai for ece students
free internship for bca
internship for computer science engineering students in india
internships in hyderabad for cse students 2018
electrical companies in hyderabad for internship
internships in chennai for cse students 2019
internships for ece students
inplant training in tcs chennai
internship at chennai
Great article, It's one of the best content in your site. I really impressed the post. Good work keep it up. Thanks for sharing the wonderful post.See also Best International School.
ReplyDeleteBest CBSE School in Ballia
I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training
This article is a great article that I have seen in my asp.net programming career so far.
ReplyDeletewebsite development company in Surat Gujarat
Thank you so much for sharing this very Useful And More Informative post. Your blog has a lot of material with clear explanations and is really effective for new readers, therefore I'm very impressed. Keep up the excellent work. Thank you for distributing this fantastic blog! Moreover, we have a website. When and whenever you see this comment, please check it out.
ReplyDeletetaxi service in Ahmedabad
cab service in Ahmedabad
taxi on rent in Ahmedabad
Great article! 🙌 I love how it explains using Canada virtual numbers to register on VK without revealing your personal phone number. It's a smart way to keep your privacy intact while still enjoying all the features of the platform. 👍 Definitely going to check out PVApins for easy and secure VK sign-ups! 🌟
ReplyDeleteUsing a virtual phone number from PVAPins for signing up on Match is such a smart way to protect your privacy! 🛡️ It's super easy to follow the steps and avoid the hassle of spam calls or data breaches. Definitely a great option for anyone who wants a secure and private online dating experience. Highly recommend it! 📱💖
ReplyDeleteVisit us:- https://pvapins.com/?/EN
Using a Belgium virtual number for signing up on Line via PVApins is such a smart way to protect your privacy! It's great to see how easy and affordable it is to keep your personal phone number hidden while still enjoying all the features Line offers. I love that it allows anonymous sign-ups and ensures online security. Definitely a must-try for anyone looking to enhance their privacy during account registration! #PrivacyMatters #SecureSignUp
ReplyDeleteVisit us:- https://pvapins.com/?/EN