Control/login.ascx.cs

(完整代码) 2KB

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.SqlClient;
public partial class Control_login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
      SqlConnection   cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
        cn.Open();
       SqlCommand  cmd = new SqlCommand("select*from userinfo where username='" + this.txtusername.Text.ToString().Trim() + "' and pwd='" + this.txtpwd.Text.ToString().Trim() + "'and role='"+this.ddlrole .SelectedItem .Value .ToString ()+"'", cn);
       SqlDataReader dr;
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Session["id"] = dr["id"];
            Session["username"] = dr["username"].ToString();
            Session["role"] = dr["role"].ToString();
            Session["pwd"] = dr["pwd"].ToString();
            Session ["entertime"]=dr["entertime"].ToString ();
            Session["loginouttime"] = dr["loginouttime"].ToString();
            Session["loginnum"] = dr["loginnum"].ToString();
            dr.Close();
            SqlCommand cmd1 = new SqlCommand("update userinfo set logintime=getdate(),loginnum=loginnum+1,attr='在线' where id=" + Convert.ToInt32(Session["id"]), cn);
            cmd1.ExecuteNonQuery();

            cn.Close();
            System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.txtusername.Text,false);
            //Response.Redirect("Default.aspx");
        }
        else
        {
            this.Labmessage.Text = "用户名或密码错误";
        }
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        this.txtpwd.Text = "";
        this.txtusername.Text = "";
        this.txtusername.Focus();
        this.Labmessage.Text = "";

    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。