用户验证一:

admin文件夹下有login.asp,conn.asp,check.asp,index.asp,data文件夹下是data.mdb,数据库中有数据表admin,表结构是id,自动编号,username,文本,password,文本
       下面是各文件的代码:
       index.asp
       <%
         if not session("check")="checked" then
             response.Redirect "login.asp"
         else
       %>
      <html>
        <head>
           <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
           <title>后台管理</title>
        </head>
        <frameset cols="100,*" border="1" framespacing="1" rows="*">
        <frame name="left" scrolling="auto" src="left.asp" />
        <frame name="right" scrolling="auto" src="right.asp"  />
        </frameset><noframes></noframes>
        <noframes>
      </html>
    <%
      end if
     %>

     conn.asp
     <%
       Set conn=server.CreateObject("adodb.connection")
       connstr="provider=microsoft.jet.oledb.4.0;data source="&server.mappath("../data/data.mdb")
       conn.open connstr
     %>

    login.asp
    <html>
     <head>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
      <title>后台登陆验证</title>
     </head>
     <body>
       <form  name="form1" method="post" action="check.asp">
           <div align="center">
           <p>&nbsp;</p>
           <p>后台管理系统入口</p>
           </div>
          <div align="center"><br />
           帐号:
          <input type="text" name="username" />
           <br />
           <br />
          密码:
          <label>
           <input type="password" name="password" />
          </label>
          </div>
          <p align="center">
           <label>
            <input type="submit" name="Submit1" value="提交" />
           </label>
           <label>
           <input type="reset" name="Submit2" value="重置" />
           </label>
           </p>
        </form>
        </body>
       </html>

      check.asp
      <!--#include file="conn.asp"-->
      <title>嗨,出错了!</title>
       <%
         username=replace(request.form("username"),"'","''")
         password=replace(request.form("password"),"'","''")
         sql="select * from admin where(username='"&username&"' and password='"&password&"')"
         set rs=server.createobject("adodb.recordset")
         rs.open sql,conn,1,1
         if not rs.eof then
         rs.close
         conn.close
         session("check")="checked"
         response.Redirect "index.asp"
        else
        session("check")=""
        response.write ("对不起,密码错误,请重新核对后再登陆!")
        end if
        %>

 

用户验证二:


先来看 login.htm 页面 

     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
     <title>登录</title> 
     </head>
     <body> 
        <form name="form1" method="post" action="logincheck.asp">
          <table width="200" border="1" align="center" cellpadding="0" cellspacing="0"> 
          <tr> 
          <td colspan="2"><div align="center">登录</div></td>
          </tr>
          <tr> 
          <td width="57"><div align="center">用户名</div></td>
          <td width="137" valign="top"><input name="username" type="text"  id="username" size="25"></td> 
          </tr>
          <tr> 
          <td><div align="center">密码</div></td> 
          <td valign="top"><input name="password" type="password"  id="password" size="25"></td>
          </tr>
          <tr> 
          <td colspan="1"><div align="center"> 
          <input type="submit" name="Submit" value="提交">
          </div></td>
          </tr>
          </table>
        </form>
      </body>
      </html>

    后台验证页面 logincheck.asp

     <%
      dim username,password 
      username=request.form("username")
      password=request.form("password")
      set rs=server.createobject("adodb.recordset") 
      conn = "DBQ=" + server.mappath("user.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
      sql="select * from user where y_user='"&username&"'"
      rs.open sql,conn,1,1
      if rs.eof then 
      response.write "<script>alert('登录失败');history.back();</script>"
      response.end
      else 
      if rs("y_pass")<>password then
      response.write "<script>alert('登录失败');history.back();</script>"
      response.end     
      end if      
      session("admin")=username
      response.write"<script>alert('登录成功');location.href='index.asp'</script>"
      end if 
     %>

    数据库用access,数据库名:user.mdb
         数据表名:user
         用户名字段:y_user,密码字段:y_pass.