473,789 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

facing problem in password reset in asp.net

1 New Member
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.Collecti ons.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.Secu rity;

public partial class Password_recove ry : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

if (!Membership.En ablePasswordRes et)
{
FormsAuthentica tion.RedirectTo LoginPage("Defa ult.aspx");
}

Msg.Text = "";

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


}
public void VerifyUsername( )
{
MembershipUser u;
u = Membership.GetU ser(UsernameTex tBox.Text, false);
if (u == null)
{
Msg.Text="Usern ame"+ Server.HtmlEnco de(UsernameText Box.Text) +"notfound. Please check the value and re-enter.";
QuestionLabel.T ext = "";
QuestionLabel.E nabled = false;
AnswerTextBox.E nabled = false;
ResetPasswordBu tton.Enabled = false;

}
else
{
QuestionLabel.T ext = u.PasswordQuest ion;
QuestionLabel.E nabled = true;
AnswerTextBox.E nabled = true;
ResetPasswordBu tton.Enabled = true;
}


}

protected void ResetPassword_O nClick(object sender, EventArgs e)
{
MembershipUser u;
string newPassword;
u = Membership.GetU ser(UsernameTex tBox.Text, false);

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

try
{
newPassword = u.ResetPassword (AnswerTextBox. Text);
}
catch (MembershipPass wordException 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.HtmlEnco de(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="Passw ord-recovery.aspx.c s" Inherits="Passw ord_recovery" %>

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

<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="maro on" /><br />

Username: <asp:Textbox id="UsernameTex tBox" Columns="30" runat="server" AutoPostBack="t rue" />
<asp:RequiredFi eldValidator id="UsernameReq uiredValidator" runat="server"
ControlToValida te="UsernameTex tBox" ForeColor="red"
Display="Static " ErrorMessage="R equired" /><br />

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

Answer: <asp:TextBox id="AnswerTextB ox" Columns="60" runat="server" Enabled="false" />
<asp:RequiredFi eldValidator id="AnswerRequi redValidator" runat="server"
ControlToValida te="AnswerTextB ox" ForeColor="red"
Display="Static " ErrorMessage="R equired" Enabled="false" /><br />

<asp:Button id="ResetPasswo rdButton" Text="Reset Password"
OnClick="ResetP assword_OnClick " runat="server" Enabled="false" />


<br />
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataBase_Con nection %>"
SelectCommand=" SELECT [id], [user_name], [password], [f_name], [secreat-question] AS column1, [l_name], [secreat-answer] AS column2 FROM [user_account]">
</asp:SqlDataSour ce>


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

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

Similar topics

1
3698
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 password resets to this user. Security policies within the company dictate that the password for this domain account cannot be permenant. Would there be any way to automatically reset the pwd in these
3
2377
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 the domain they are promoted for a new password? I know the code will have to run under the Admin. That is fine I just need to know what the API is and how to use it.
0
940
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. The local account will be reset from that web application. I have the Following. string pathname = "WinNT://myMachine/"; DirectoryEntry usr = new DirectoryEntry(pathname);
1
1402
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 the password (perhaps a new temporary one) to the e-mail address if it is a valid address in the db for the site. I'm looking for opinions and perspective on implementing something similar. I understand that doing this would open up additional...
0
2346
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 think the get_random_word function is not working right. Here are the scripts: This is the script after the user enters his/her userid. <?php require_once("bookmark_fns.php"); // creating short variable name $username = $_POST;
1
1541
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 emails are getting through which puzzles me. <system.net> <mailSettings> <smtp from="admin@mydomain.com" > <network host="mail.myhost.com" password="mypwd"
3
1699
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
9933
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 exactly. We currently have an intranet app built in a mixture of asp and asp.net 1.1 and 2.0 written in VB .Net. We have a form where the user logs in and it authenticates against active directory successully in 2 ways: 1. The admin resets the...
3
5148
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 get into the network remotely using his account (for remote desktop). is there a way to reset his password for the domain on his laptop without physically being connected to the domain? i have looked into password reset tools, but if there is a...
5
2074
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 be applied to the SUSE system that will remove(delete) a specific folder on the system if a threat is defected - see example below If the "root" user password is reset throw the single user mode (using the passwd function); will the setup (or...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.