各位高手帮个忙,我是新手,想用C#.NET实现个找回密码的功能,就是根据帐号,密保问题和答案找回密码。
表名比如是getpassword,表里有Userid(帐号),Userpassword(密码),Userquestion(保护问题),Useranswer(问题答案)如果...
表名比如是getpassword,表里有Userid(帐号),Userpassword(密码),Userquestion(保护问题),Useranswer(问题答案)
如果帐号.保护问题.问题答案都和数据库里的一致的话,然后用个textbox输出密码!!各位大哥帮个忙,在下谢谢了~ 展开
如果帐号.保护问题.问题答案都和数据库里的一致的话,然后用个textbox输出密码!!各位大哥帮个忙,在下谢谢了~ 展开
4个回答
展开全部
//帮你编了个完整,简单易懂代码:
//数据库跟你的一样,我用的是Access的数据库
//前台代码
//=============================
<%@ 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 = "您的回答不正确";
}
}
}
//数据库跟你的一样,我用的是Access的数据库
//前台代码
//=============================
<%@ 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 = "您的回答不正确";
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string userid="Select Useranswer from getpassword where Userid = '" +Textbox1.Text.Tostring()+"'"
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds);
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string userid="Select Useranswer from getpassword where Userid = '" +Textbox1.Text.Tostring()+"'"
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds); 这样就OK了
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds); 这样就OK了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不会
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询