程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp完整登陸代碼

asp完整登陸代碼

日期:2017/1/9 13:41:16      編輯:關於ASP編程

    asp完整登陸代碼
    <%
    option explicit
    強制浏覽器重新訪問服務器下載頁面,而不是從緩存讀取頁面
    Response.Buffer = True
    Response.Expires = -1
    Response.ExpiresAbsolute = Now() - 1
    Response.Expires = 0
    Response.CacheControl = "no-cache"
    主要是使隨機出現的圖片數字隨機
    %>
    <!--#include file="inc/config.asp"-->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE><%=rs_config("c_incname")%>-管理員登錄</TITLE>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <LINK href="inc/login.css" rel=stylesheet type=text/css>
    <base target="main">
    <style type="text/css">
    <!--
    .style2 {font-size: 12pt}
    -->
    </style>
    <SCRIPT language=JavaScript>
    <!--
    function frmSubmit() {

     if (theForm.name.value == "") {
      alert("請輸入用戶名");
      theForm.name.focus();
      return false;
     }
     if (theForm.pass.value == "") {
      alert("請輸入密碼");
      theForm.pass.focus();
      return false;
    }
     if (theForm.safecode.value == "") {
      alert("請輸入校驗碼");
      theForm.safecode.focus();
      return false;
    }

     return true;
    }
    //-->
    </SCRIPT>
    <link rel="icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <LINK
    href="images/WEI.css" type=text/css rel=stylesheet>
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>
    </HEAD>
    <BODY bgColor=#ffffff>
    <BR>
    <br>
    <br>
    <br>
    <br>
    <BR>
    <TABLE align="center" cellSpacing=0 cellPadding=0 width=555 border=0 style="border-collapse: collapse" bordercolor="#111111">
    <TBODY>
    <TR>
    <TD width="588">
    <TABLE align="center" cellSpacing=0 cellPadding=0 width=558 border=0 style="border-collapse: collapse" bordercolor="#111111">
    <TBODY>
    <TR>
    <TD vAlign=top width="360" height="104">
    <FORM action=logincheck.asp method=POST target="_top">
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2"><img src="images/Admin_Login1.gif" width="600" height="126"></td>
      </tr>
      <tr>
        <td width="508" valign="top" background="Images/Admin_Login2.gif"><table width="508" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="37" colspan="6">&nbsp;</td>
            </tr>
            <tr>
              <td width="75" rowspan="2">&nbsp;</td>
              <td width="126"><font color="#043BC9">用戶名稱:</font></td>
              <td width="39" rowspan="2">&nbsp;</td>
              <td width="131"><font color="#043BC9">用戶密碼:</font></td>
              <td width="34">&nbsp;</td>
              <td width="103"><font color="#043BC9">驗證碼:<b><font color=#ff0000><IMG
                                  src="inc/Code.asp" width="40" height="10" align="absmiddle"></font></b></font></td>
            </tr>
            <tr>
              <td><input name=name id="name" size=15></td>
              <td><input name=pass type=password id="pass" size=12></td>
              <td>&nbsp;</td>
              <td><INPUT name="safecode" type=text id="safecode" size=12></td>
              </tr>
        </table></td>
        <td>
          <input type="image" name="Submit" src="Images/Admin_Login3.gif" style="width:92px; HEIGHT: 126px;"></td>
      </tr>
    </table>
    </FORM>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </BODY>
    </HTML>

    下面是asp處理文件
     <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

    <!--#include file="conn.asp"-->
    <!--#include file="md5.asp"-->

    <%
    function ChkPost()
     dim server_v1,server_v2
     chkpost=false
     server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
     server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
     if mid(server_v1,8,len(server_v2))<>server_v2 then
      chkpost=false
     else
      chkpost=true
     End if
    End function
    session.Timeout=20
    if ChkPost=false then
      'emsg="請不要從其它站點提交表"
         response.Redirect("login.asp?emsg=請不要從其它站點提交表")
         Response.End()
    End if

    dim aname,apass,FoundErr,ErrMsg
    FoundErr=False
    aname=replace(trim(request("name")),"'","")
    apass=replace(trim(request("pass")),"'","")
    safecode=replace(trim(Request("safecode")),"'","")
    if len(aname)>20 or len(aname)<3  then
       FoundErr=True
       ErrMsg=ErrMsg&"用戶名不對!nn"
    End if

    if len(apass)>20 or len(apass)<6  then
       FoundErr=True
       ErrMsg=ErrMsg&"用戶密碼不對!nn"
    End if
    if Safecode="" then
     FoundErr=True
     ErrMsg=ErrMsg & "驗證碼不能為空!nn"
    end if
    if Session("Admin_GetCode")="" then
     FoundErr=True
     ErrMsg=ErrMsg & "你登錄時間過長,請重新返回登錄頁面進行登錄。nn"
    end if
    if Safecode<>CStr(Session("Admin_GetCode")) then
     FoundErr=True
     ErrMsg=ErrMsg & "您輸入的確認碼和系統產生的不一致,請重新輸入。nn"
    end if
    if FoundErr=True then
       Call LoginError(ErrMsg)
       Conn.close
       Set Conn=Nothing
    else

    apass=md5(apass)
    dim sql,rs
    sql="select a_name,a_pass,a_flag from admin where a_name='"&aname&"' and a_pass='"&apass&"'"
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
    if rs.BOF and rs.EOF then
        ErrMsg="用戶名或是密碼錯誤!"
     Call LoginError(ErrMsg)
    rs.close
    set rs=Nothing
    conn.close
    set conn=Nothing
    response.End
    elseif Not(rs.BOF or rs.EOF) then
    session("aname")=rs("a_name")
    session("admin_flag")="into"
    session("admin_sys")=rs("a_flag")
    response.Redirect("useradmin.asp")
    rs.close
    set rs=Nothing
    conn.close
    set conn=Nothing
    response.End
    End if
    end if

    Sub LoginError(EMsg)
        response.write "<script language='javascript'>" & chr(13)
        response.write "alert('"&EMsg&"');" & Chr(13)
        response.write "window.document.location.href='login.asp';"&Chr(13)
        response.write "</script>" & Chr(13)
        Response.End
    End Sub

     %>

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved