Skip to main content
 首页 » 编程设计

c#之在 asp.net 中获取 BIOS 日期

2024年01月26日40luoye11

我检查管理员是否有许可证所以我现在按月检查登录我正在使用系统日期进行检查但管理员更改系统日期所以我想要日期 BIOS 日期

string crt_val = "",crt_mont = "",crt_year = ""; 
dt_v = objdata.select_upload(); 
if (dt_v.Rows.Count > 0) 
{ 
    crt_val = dt_v.Rows[0]["val"].ToString(); 
    crt_mont = dt_v.Rows[0]["mon"].ToString(); 
    crt_year = dt_v.Rows[0]["yer"].ToString(); 
    //yy = Convert.ToInt32(crt_year); 
} 
else 
{ 
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true); 
    return; 
} 
if (Verification.Trim() != "") 
{ 
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true); 
    return; 
} 
string fin=""; 
string oyear = ""; 
oyear = DateTime.Now.Year.ToString(); 
int nyear = DateTime.Now.Year + 1; 
int smonth = Convert.ToInt32(DateTime.Now.ToString("MM")); 
fin = oyear + "-" + nyear.ToString(); 
int num; 
switch (crt_mont) 
{ 
    case ("January"): 
        num = 1; 
        break; 
    case ("February"): 
        num = 2; 
        break; 
    case ("March"): 
        num = 3; 
        break; 
    case ("April"): 
        num = 4; 
        break; 
    case ("May"): 
        num = 5; 
        break; 
    case ("June"): 
        num = 6; 
        break; 
    case ("July"): 
        num = 7; 
        break; 
    case ("August"): 
        num = 8; 
        break; 
    case ("September"): 
        num = 9; 
        break; 
    case ("October"): 
        num = 10; 
        break; 
    case ("November"): 
        num = 11; 
        break; 
    default: 
        num = 12; 
        break; 
} 
if ((num < smonth) || (num == smonth)) 
{ 
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true); 
} 
else 
{ 
    if (crt_val == "0") 
    { 
        Session["UserId"] = txtusername.Text.Trim(); 
        objuser.UserCode = txtusername.Text.Trim(); 
        objuser.Password = s_hex_md5(txtpassword.Text.Trim()); 
        string pwd = s_hex_md5(txtpassword.Text); 
        objuser.Ccode = ddlCode.SelectedValue; 
        objuser.Lcode = ddlLocation.SelectedValue; 
        DataTable dt = new DataTable(); 
        dt = objdata.UserLogin(objuser); 
        if (dt.Rows.Count > 0) 
        { 
            if ((dt.Rows[0]["UserCode"].ToString().Trim() == txtusername.Text.Trim()) && (dt.Rows[0]["Password"].ToString().Trim() == pwd) && (dt.Rows[0]["CompCode"].ToString().Trim() == ddlCode.SelectedValue) && (dt.Rows[0]["LocationCode"].ToString().Trim() == ddlLocation.SelectedValue)) 
            { 
                Session["Isadmin"] = dt.Rows[0]["IsAdmin"].ToString().Trim(); 
                Session["Usernmdisplay"] = txtusername.Text.Trim(); 
                Session["Ccode"] = dt.Rows[0]["CompCode"].ToString().Trim(); 
                Session["Lcode"] = dt.Rows[0]["LocationCode"].ToString().Trim(); 
                if (Session["Isadmin"].ToString() == "1") 
                { 
                    Session["RoleCode"] = "1"; 
                } 
                else 
                { 
                    Session["RoleCode"] = "2"; 
                } 
                Response.Redirect("Dashboard.aspx"); 
            } 
            else 
            { 
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('User Name and Password Wrong');", true); 
            } 
        } 
        else 
        { 
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Window", "alert('Please Update your Licence Key');", true); 
        } 
    } 
    else 
    { } 
} 

请您参考如下方法:

获取 BIOS 日期不会改变任何东西,因为如果有人更改系统日期,硬件实时时钟也会更改。

更好的选择是在客户端计算机之外检查日期,例如检查一些 URL。