coding for change password

Posted by reddysankark-13471 under ASP.NET on 2/27/2012 | Points: 10 | Views : 24327 | Status : [Member] | Replies : 13
hi,
i need code for change password with out using change password control.

sankarreddy


Responses

Posted by: Blessyjees on: 2/27/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You can use another page or different area for the same page. When we click on the change page button , shows the another page or same page portion. In this section you can add old password, newpassword textboxes and labels and change password button. When we click on this button, you should update the database entry of the corresponding user with new password.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/27/2012 [Member] Starter | Points: 25

Up
0
Down
COULD PLEASE GIVE ME C# CODING FOR THIS

sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/27/2012 [Member] Starter | Points: 25

Up
0
Down
COULD YOU PLEASE GIVE ME C# CODING FOR THIS

sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/27/2012 [Member] Silver | Points: 25

Up
0
Down
I didnot get it properly

Thanks,
Sanjay

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/28/2012 [Member] Starter | Points: 25

Up
0
Down
HI,

I NEED CODING FOR CHANGE PASSWORD WITH OUT USING THAT CHANGE PASSWORD CONTROL.WE CAN USE THAT CHANGE PASSWORD CONTROL MEANS IT WILL ASK MEMBERSHIP CLASS.I DONT WANT THAT MEMBERSHIP CLASS CODING.I AM NEW THIS CODING COULD YOU PLEASE GIVE ME THIS CODING AS EARLY AS POSSBILE ITS TO URGENT

sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pradeepkumar417 on: 2/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,


Go through the attachment file
 Download source file

Thanks & Regards,
Software Engineer,
Pradeep Kumar

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Sample code is

Consider your design code like this

<table cellpadding="0" cellspacing="0" width="100%">

<tr>
<td class="portmaingreyHead" style="padding-left:10px">User ID</td>
<td><asp:TextBox ID="UserId" ReadOnly="true" Runat="server" CssClass="TblBorder"></asp:TextBox></td>
</tr>
<tr>
<td class="portmaingreyHead" style="padding-left:10px">Old Password</td>
<td><asp:TextBox ID="Pwd" TextMode="Password" Runat="server" CssClass="TblBorder"></asp:TextBox></td>
</tr>
<tr>
<td class="portmaingreyHead" style="padding-left:10px">New Password</td>
<td><asp:TextBox ID="NPwd" TextMode="Password" Runat="server" CssClass="TblBorder"></asp:TextBox></td>
</tr>
<tr>
<td class="portmaingreyHead" height="20" style="padding-left:10px">Confirm Password&nbsp;</td>
<td><asp:TextBox ID="CPwd" TextMode="Password" Runat="server" CssClass="TblBorder"></asp:TextBox></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<asp:ImageButton ID="Submit" ImageUrl="/images/submit.gif" OnClick="Submit_Click" runat="server" />
&nbsp;&nbsp;
<asp:ImageButton ID="Cancel" runat="server" ImageUrl="/images/Cancel.gif" OnClick="Cancel_Click" />
</td>
</tr>
</table>



------------------------------------------------------
Now see the code behind part

you declare variables and set connection path, etc. Now we see the submit button logic

The string SqlCon defines your connection path

protected void Submit_Click(object sender, ImageClickEventArgs e)

{

string sql="select * from siteuser where UserId ='" + _UserID + "' and Password='"+ Pwd.Text.Trim() +"'";
DataSet ds = SqlHelper.ExecuteDataset(SqlCon, CommandType.Text, sql);
if (ds.Tables[0].Rows.Count > 0)
{
sqlNew = "update siteuser set Password = '" + NPwd.Text.Trim() + "' where UserId ='" + _UserID + "'";
SqlHelper.ExecuteNonQuery(SqlCon, CommandType.Text, sqlNew);


Response.Write("<script language=Javascript>alert('Your Password Has Been Changed,Please Login With New Password');document.location='/Login.aspx';</script>");
}

}




Thanks & Regards,
Pasupathi G
No Pain No Gain

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Kindly go through this link

http://www.asp.net/cssadapters/Membership/ChangePassword.aspx

Thanks & Regards,
Pasupathi G
No Pain No Gain

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/28/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
i can check your coding but it showing error in sqlhelper.

sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 2/29/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Please specify the error that your are getting

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/29/2012 [Member] Starter | Points: 25

Up
0
Down
cs file coding

using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
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;


public partial class changepassword : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{


}

protected void Submit_Click(object sender, EventArgs e)
{

string a, b;
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["sampleConnectionString2"].ToString();
SqlDataAdapter da = new SqlDataAdapter("select username,password from register where username='" + UserId.Text + "',password='" + Pwd.Text + "'",con);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Count; i++)
{
a = ds.Tables[0].Rows[i]["username"].ToString();
b = ds.Tables[0].Rows[i]["password"].ToString();
if (a == UserId.Text && b == Pwd.Text)
{
//SqlCommand cmd=new SqlCommand(
SqlDataAdapter sda = new SqlDataAdapter("update register set Password = '" + NPwd.Text.Trim() + "' where UserId ='" + UserId.Text + "'",con);
sda.Fill(ds);

Response.Write("<script language=Javascript>alert('Your Password Has Been Changed,Please Login With New Password')</script>");
}
else
{
Response.Write("<script language=Javascript>alert('password')</script>");
}
}
}
}


design coding

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="changepassword.aspx.cs" Inherits="changepassword" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Change Password</title>
</head>
<body bgcolor="#CCFFFF">
<center>
<h1><u>Online Shopping Cart</u></h1></center>
<form id="form1" runat="server">
<div>
<p align="center"><font size="5"><b>Change Password</b></font></p>
<asp:Panel style="position:absolute; top: 143px; left: 458px; height :182px; width: 340px; margin-top: 3px;" ID="Panel1"
runat="server" BackColor="Silver" BorderColor="#660033"
BorderStyle="Solid" HorizontalAlign="Center" ScrollBars="Vertical">
<table align="center" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td style="padding-left:10px">
User ID</td>
<td>
<asp:TextBox ID="UserId" Runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:10px">
Old Password</td>
<td>
<asp:TextBox ID="Pwd" Runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:10px">
New Password</td>
<td>
<asp:TextBox ID="NPwd" Runat="server" CssClass="TblBorder" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td height="20" style="padding-left:10px">
Confirm Password&nbsp;</td>
<td>
<asp:TextBox ID="CPwd" Runat="server" CssClass="TblBorder" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td height="5">
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Submit" runat="server" OnClick="Submit_Click" />
&nbsp;&nbsp; <%--<asp:Button ID="Cancel" runat="server" OnClick="Cancel_Click" />
--%></td>
</tr>
</table>

</asp:Panel>
</div>
</form>
</body>
</html>


sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: reddysankark-13471 on: 2/29/2012 [Member] Starter | Points: 25

Up
0
Down
cs file coding

using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
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;


public partial class changepassword : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{


}

protected void Submit_Click(object sender, EventArgs e)
{

string a, b;
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["sampleConnectionString2"].ToString();
SqlDataAdapter da = new SqlDataAdapter("select username,password from register where username='" + UserId.Text + "',password='" + Pwd.Text + "'",con);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Count; i++)
{
a = ds.Tables[0].Rows[i]["username"].ToString();
b = ds.Tables[0].Rows[i]["password"].ToString();
if (a == UserId.Text && b == Pwd.Text)
{
//SqlCommand cmd=new SqlCommand(
SqlDataAdapter sda = new SqlDataAdapter("update register set Password = '" + NPwd.Text.Trim() + "' where UserId ='" + UserId.Text + "'",con);
sda.Fill(ds);

Response.Write("<script language=Javascript>alert('Your Password Has Been Changed,Please Login With New Password')</script>");
}
else
{
Response.Write("<script language=Javascript>alert('password')</script>");
}
}
}
}


design coding

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="changepassword.aspx.cs" Inherits="changepassword" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Change Password</title>
</head>
<body bgcolor="#CCFFFF">
<center>
<h1><u>Online Shopping Cart</u></h1></center>
<form id="form1" runat="server">
<div>
<p align="center"><font size="5"><b>Change Password</b></font></p>
<asp:Panel style="position:absolute; top: 143px; left: 458px; height :182px; width: 340px; margin-top: 3px;" ID="Panel1"
runat="server" BackColor="Silver" BorderColor="#660033"
BorderStyle="Solid" HorizontalAlign="Center" ScrollBars="Vertical">
<table align="center" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td style="padding-left:10px">
User ID</td>
<td>
<asp:TextBox ID="UserId" Runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:10px">
Old Password</td>
<td>
<asp:TextBox ID="Pwd" Runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:10px">
New Password</td>
<td>
<asp:TextBox ID="NPwd" Runat="server" CssClass="TblBorder" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td height="20" style="padding-left:10px">
Confirm Password&nbsp;</td>
<td>
<asp:TextBox ID="CPwd" Runat="server" CssClass="TblBorder" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td height="5">
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Submit" runat="server" OnClick="Submit_Click" />
&nbsp;&nbsp; <%--<asp:Button ID="Cancel" runat="server" OnClick="Cancel_Click" />
--%></td>
</tr>
</table>

</asp:Panel>
</div>
</form>
</body>
</html>



this code showing an error please rectify it

sankarreddy

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.Saravanan on: 3/6/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi SankarReddy,

Is your problem resolved or not?

Note: Don't use/declare variable "i" in our DNF. Because brace of "i" consider as italic format.

Thanks,
T.Saravanan

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response