473,406 Members | 2,710 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,406 software developers and data experts.

facing problem in password reset in asp.net

1
hi to all my friends,

i have created a login system and a password recovery page i used the following code but when i run the application then it is giving me the error that username is not found although the username is already exists in database my sqlserver 2005 is coonected with a proper connection strings please help me out regarding to this my codes are as follows::

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

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

if (!Membership.EnablePasswordReset)
{
FormsAuthentication.RedirectToLoginPage("Default.a spx");
}

Msg.Text = "";

if (!IsPostBack)
{
Msg.Text = "Please supply a username.";
}
else
{
VerifyUsername();
}


}
public void VerifyUsername()
{
MembershipUser u;
u = Membership.GetUser(UsernameTextBox.Text, false);
if (u == null)
{
Msg.Text="Username"+ Server.HtmlEncode(UsernameTextBox.Text) +"notfound. Please check the value and re-enter.";
QuestionLabel.Text = "";
QuestionLabel.Enabled = false;
AnswerTextBox.Enabled = false;
ResetPasswordButton.Enabled = false;

}
else
{
QuestionLabel.Text = u.PasswordQuestion;
QuestionLabel.Enabled = true;
AnswerTextBox.Enabled = true;
ResetPasswordButton.Enabled = true;
}


}

protected void ResetPassword_OnClick(object sender, EventArgs e)
{
MembershipUser u;
string newPassword;
u = Membership.GetUser(UsernameTextBox.Text, false);

if (u == null)
{
Msg.Text = "Username " + Server.HtmlEncode(UsernameTextBox.Text) + " not found. Please check the value and re-enter.";
return;
}

try
{
newPassword = u.ResetPassword(AnswerTextBox.Text);
}
catch (MembershipPasswordException ex)
{
Msg.Text = "Invalid password answer. Please re-enter and try again.";
return;
}
catch (Exception ex)
{
Msg.Text = ex.Message;
return;
}

if (newPassword != null)
{
Msg.Text = "Password reset. Your new password is: " + Server.HtmlEncode(newPassword);
}
else
{
Msg.Text = "Password reset failed. Please re-enter your values and try again.";
}

}


}

and its aspx file is::

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Password-recovery.aspx.cs" Inherits="Password_recovery" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<h3>Retrieve Password</h3>

<asp:Label id="Msg" runat="server" ForeColor="maroon" /><br />

Username: <asp:Textbox id="UsernameTextBox" Columns="30" runat="server" AutoPostBack="true" />
<asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
ControlToValidate="UsernameTextBox" ForeColor="red"
Display="Static" ErrorMessage="Required" /><br />

Password Question: <b><asp:Label id="QuestionLabel" runat="server" /></b><br />

Answer: <asp:TextBox id="AnswerTextBox" Columns="60" runat="server" Enabled="false" />
<asp:RequiredFieldValidator id="AnswerRequiredValidator" runat="server"
ControlToValidate="AnswerTextBox" ForeColor="red"
Display="Static" ErrorMessage="Required" Enabled="false" /><br />

<asp:Button id="ResetPasswordButton" Text="Reset Password"
OnClick="ResetPassword_OnClick" runat="server" Enabled="false" />


<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataBase_Connection %>"
SelectCommand="SELECT [id], [user_name], [password], [f_name], [secreat-question] AS column1, [l_name], [secreat-answer] AS column2 FROM [user_account]">
</asp:SqlDataSource>


</form>
</body>
</html>
Feb 12 '11 #1
0 1040

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

Similar topics

1
by: Kannan | last post by:
Hello, I hope you guys can help me with a problem that I am facing... I have started the MSSqlServer service and SQLServerAgent services with a domain username and password. There are periodic...
3
by: Ian | last post by:
Hi I know there are products out there that can do this like http://www.psynch.com/technology/ska.html What is the code that is used to Reset a Users password so the next time they logon to...
0
by: Dustin | last post by:
Hey everyone, Im having some issues with my app resetting a users local account. They will be accessing the website from a domain account however logging into the website with a local account....
1
by: Alfred E. Newman | last post by:
I want to enable visitors who have forgotten their password to request a new one. I have seen that some sites simply require users to enter their e-mail address. Then the server-side logic sends...
0
by: serkan | last post by:
Guys, I am trying to get this password reset functionality wor for me but I am not successful at all. Please somebody help me. I get "Your password could not be reset - please try again later" so I...
1
by: Dabbler | last post by:
My password reset emails aren't getting through so I have two problems, getting the email to work and resetting the passwords from users who have already missed their reset email. My health...
3
by: john_c | last post by:
Using asp.net Membership, is there a way to detect a password reset so that next time the user logs in, you can send them to the password change page? Thanks.
6
by: jarice1978 | last post by:
Hello, I have been scanning the internet for a few days now. That is not working. So now it is time to post! I have read a few other posts on here about authentication but they do not match...
3
by: mpmason14 | last post by:
we have a user that is on his laptop at a conference. over the weekend he changed his password on the laptop but - surprise! - forgot the password. he is still away at the conference and needs to...
5
by: wolfjmt | last post by:
Hi all I am new to Linux, I have worked on it a little before (on Redhat 8 ), but still consider myself a novas and open SUSE is completely new to me. I was told that there are setting that can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.