日期:2014-05-18 浏览次数:20444 次
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack || Convert.ToBoolean(Session["judge"]) == false) { bind(); lblName2.Text = "您尚未登录"; } else { Session["judge"] = true; Session["mail"] = txtUserMail.Text; Panel1.Visible = false; Panel2.Visible = true; lblName.Text = "Hello~" + Convert.ToString(Session["mail"]); lblName2.Text = Convert.ToString(Session["mail"]) + "您可以发表留言"; } }
protected void Button1_Click(object sender, EventArgs e) { string dataPath = Server.MapPath("access/DataBase.mdb"); OleDbConnection con = DB.con(dataPath); con.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Parameters.Add("@userMail", OleDbType.VarChar, 50); cmd.Parameters["@userMail"].Value = txtUserMail.Text; cmd.Parameters.Add("@userPWD", OleDbType.VarChar, 20); cmd.Parameters["@userPWD"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(txtuserPWD.Text, "md5"); cmd.CommandText = "select count(*) from userinfo where userMail = @userMail and userPWD = @userPWD"; cmd.Connection = con; int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count == 1) { Session["judge"] = true; Session["mail"] = txtUserMail.Text; Panel1.Visible = false; Panel2.Visible = true; lblName.Text = "Hello~"+Convert.ToString(Session["mail"]); lblName2.Text = Convert.ToString(Session["mail"])+"您可以发表留言"; OleDbCommand IDcmd = new OleDbCommand("select ID from userinfo where userMail ='"+txtUserMail.Text+"'", con); Session["ID"]=Convert.ToString(IDcmd.ExecuteScalar()); } else { Session["judge"] = false; Response.Write("登录失败!帐号或者密码错误!"); } con.Close(); }
<asp:Panel ID="Panel1" runat="server" Height="12px" Width="90%"> 用户名:<asp:TextBox ID="txtUserMail" runat="server"></asp:TextBox> 密码:<asp:TextBox ID="txtuserPWD" runat="server" TextMode="Password"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_Click" /> <asp:Button ID="btnClear" runat="server" OnClick="btnClear_Click" Text="清空" /> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="lbtnReg_Click">注册</asp:LinkButton></asp:Panel> <asp:Panel ID="Panel2" runat="server" Height="12px" Width="90%" Visible="False"> <div style="text-align:left;background:dark