ASP調用域用戶驗證

        最近,領導又要求做一個簡單的薪金查詢小平臺。還好,我雖然對ASP和設計不是精通,但還是有點熟悉。以前,也修改過幾個系統和做過幾個小程序。這一次已經不是第一次了,所以做起來不會無從下手。看來,積累基礎知識和實戰應用確實很有好處。
        好了,廢話不多說了,入正題。由於公司是域環境,所以在很多時候,用戶的安全性與管理性非常方便。此次,也是一樣,web開發,域用戶驗證,此次數據源是Excel表,因爲,這樣人事每月錄入數據比較方便。
        第一步,域用戶驗證,用戶登錄界面。logon.asp
<html>
<body>
<table width="600" height="200" border="0">
<tr><td>
  <form   action="chkusr.asp"   method="post">  
    <div ><span class="STYLE1">域用戶:
        <input width="145"   name=id   type=text value="<%=request.cookies("id")%>">
          <br> 
          <br>
      域密碼:
      <input width="150"   type=password   name=pwd>
      <br>  
      <br>
      登錄域:
      <input width="150"   type=password   name=domain>
      <br>  
      <br>
    </span>
    <input   name=sub   type=submit   value="提交">
    </div>
  </form>  
</td>
</tr>
</table>
</body>
</html>
第二步,用戶驗證。chkusr.asp
<html>
<body>
 <script   language=javascript   RUNAT="SERVER">  
  function   logonDoADLogon(p_strDomain,   p_strUserID,   p_strPWD)  
  {               //return   true;  
  var   f_oIADS,   f_oUser,   f_oContainer;  
  var   f_blnRet   =   true;  
   
  try  
  {  
  var   f_oIADS   =   GetObject('WinNT:');  
  f_oContainer   =   f_oIADS.OpenDSObject('WinNT://'   +   p_strDomain,   p_strDomain   +   "\\"   +   p_strUserID,   p_strPWD,   0);  
   
  delete   f_oContainer;  
  delete   f_oIADS;  
  }  
  catch   (e)  
  {  
  return   false;  
  }    
   
  try  
  {  
  var   objUser   =   GetObject("WinNT://"   +   p_strDomain   +   "/"   +   p_strUserID   );  
  delete   objUser;  
  }  
  catch(e){  
  return   false;  
  }      
   
  return   true;  
  }  
  </script>  
   
  <%  
  id=trim(request("id"))  
  Response.Cookies("id")=id
  pwd=trim(request("pwd"))  
  domain=trim(request("domain"))   
  if     logonDoADLogon(domain,id,pwd)   then
 
     %>
  <script language="javascript">
   window.location.href="12.asp"
  </script>
  <%    
  else  %>
  <script language="javascript">
   alert("用戶名或密碼錯,請重新輸入!");
   window.history.back(-1);
  </script>
<%end   if%>
</body>
</html>
判斷用戶與密碼是否正確,如果正確頁面跳轉到12.asp,如果錯誤,提示錯誤信息,確定後,回到登錄界面。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章