login.aspx.cs

来自「shop sales computer, write asp.net code 」· CS 代码 · 共 63 行

CS
63
字号
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 admin_Default : System.Web.UI.Page
{
   
    int admin = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
       Session["admin"] = -1;
       Session["user"] = "";
    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
       
        if (Check2(Login1.UserName,Login1.Password))
        {
            admin = 1;
            e.Authenticated = true;            
            Session["admin"] = admin;
            Session["user"] = Login1.UserName;
            Login1.DestinationPageUrl = "Default.aspx";
            
        }       
    }
    
    bool Check2(string user, string pass)
    {
        KetNoiClass kn = new KetNoiClass();
        kn.MoKetNoi();
        DataTable dt = new DataTable();
        SqlDataAdapter adt = new SqlDataAdapter("select * from account", kn.Connection);
        adt.Fill(dt);
        string passA = FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "MD5");
        foreach (DataRow row in dt.Rows)
        {
            if (row["username"].ToString() == user)
            {
                if ((string)row["password"] == passA)
                    return true; break;
            }
        }      
        return false ;
    }
     //public string EncodePassword(string Password, string Format)
        //{
        //    if(Format == "")
        //        Format = "MD5";
        //    return FormsAuthentication.HashPasswordForStoringInConfigFile(Password, Format);
        //}
}
   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?