各位高手帮个忙,我是新手,想用C#.NET实现个找回密码的功能,就是根本帐...
发布网友
发布时间:2024-09-29 09:49
我来回答
共2个回答
热心网友
时间:2024-09-29 12:23
//呵呵~~~ 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 = "您的回答不正确";
}
}
}
热心网友
时间:2024-09-29 12:25
直接找回还是将密码发送邮箱?还有密码有没有加密等等都说清楚噻