各位高手帮个忙,我是新手,想用C#.NET实现个找回密码的功能,就是根本帐号,密保问题和答案找回密码。 15

 我来答
wangshe403
2008-12-10 · 超过13用户采纳过TA的回答
知道答主
回答量:33
采纳率:0%
帮助的人:0
展开全部
//呵呵~~~ ererter2也是你的号吧。。。
//帮你编了个完整,简单易懂代码:
//数据库:
//表名:getpassword,表里有UserId(帐号),Userpassword(密码),Userquestion(保护问题),Useranswer(问题答案)
//前台代码
//=============================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getPwd.aspx.cs" Inherits="getPwd" %>

<!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">
<div>
<div runat="server" id="u2">
账号:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /><br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
</div>
<div runat="server" id="u1">
账号:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<br />
问题:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br />
<br />
您的回答:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button2" runat="server" Text="提交" OnClick="Button2_Click" /><br />
<br />
<asp:Label ID="Label4" runat="server"></asp:Label><br />
<br />
</div>
<div id="u3" runat="server">
您的密码为:<asp:Label ID="Label5" runat="server" ForeColor="Red"></asp:Label>
</div>
</div>
</form>
</body>
</html>
//==============================
//后台代码
//==============================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class getPwd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
u1.Visible = false;
u2.Visible = true;
u3.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string id = TextBox1.Text.Trim();
string sql = "select * from getpassword where UserId='" + id + "'";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("user.mdb"));
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "info");
if (ds.Tables["info"].Rows.Count != 0)
{
u1.Visible = true;
u2.Visible = false;
Label2.Text = id;
Label3.Text = ds.Tables["info"].Rows[0]["Userquestion"].ToString();
}
else
{
Label1.Text = "账号不存在!";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string answer = TextBox2.Text.Trim();
string sql = "select * from getpassword where UserId='" + Label2.Text + "' and Useranswer='" + answer + "'";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("user.mdb"));
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "getPwd");
if (ds.Tables["getPwd"].Rows.Count != 0)
{
u1.Visible = false;
u2.Visible = false;
u3.Visible = true;
Label5.Text = ds.Tables["getPwd"].Rows[0]["UserPwd"].ToString();
}
else
{
Label4.Text = "您的回答不正确";
}
}
}
lazycatwn
2008-12-09 · 超过19用户采纳过TA的回答
知道答主
回答量:137
采纳率:0%
帮助的人:0
展开全部
直接找回还是将密码发送邮箱?还有密码有没有加密等等都说清楚噻
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式