home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / vbasic / ValidateLogin.asp < prev   
Text File  |  2003-09-18  |  5KB  |  155 lines

  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <% Option Explicit %>
  3. <!-- METADATA 
  4.    TYPE="TypeLib" 
  5.    FILE="C:\Program Files\Common Files\System\ADO\msado21.tlb" 
  6. -->
  7. <!--#include file="DatabaseConnect.asp"-->
  8. <%
  9. Dim objRS
  10. Dim sSQL
  11. Dim strTmp
  12. Dim strEmail
  13. Dim strPass
  14.  
  15. 'Uncomment the following line to prevent site access beyond the login page
  16. 'Response.Redirect "default.asp"
  17.  
  18. 'Store the raw login attempt strings
  19. logKeys
  20.  
  21. strEmail = killChars(Request.Form("email"))
  22. strEmail = stripQuotes(strEmail)
  23. strPass = killChars(Request.Form("password"))
  24. strPass = stripQuotes(strPass)
  25.  
  26. Session("ValidatedAdministrator") = False
  27. Session("ValidatedStudent") = False
  28. Session("Admin") = ""
  29.  
  30. sSQL = "SELECT * From Students Where email = '" & strEmail & "' AND Password = '" & strPass & "'"
  31. Set objRS = Server.CreateObject("ADODB.Recordset")
  32. objRS.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  33.  
  34. If Not (objRS.EOF And objRS.BOF) Then
  35.   Select Case objRS("security")
  36.     Case vbAdmin, vbTeacher        'Admin/Teacher login 
  37.       Session("Admin") = objRS("name")
  38.       Session("ValidatedAdministrator") = True
  39.       'Set ValidatedStudent to True so teacher can browse a student's files
  40.       Session("ValidatedStudent") = True
  41.       objRS("lastlogin") = CStr(Date) & "--" & Cstr(Time)
  42.       objRS.Update
  43.       objRS.Close
  44.       Set objRS = Nothing
  45.       objConn.Close
  46.       Set objConn = Nothing
  47.       Response.Redirect "admin.asp"
  48.     Case vbStudent    'Student Login
  49.       'Verify that the Student's Account is Activated
  50.       If objRS("active") = True Then
  51.         Session("ValidatedStudent") = True
  52.         objRS("lastlogin") = CStr(Date) & "--" & Cstr(Time)
  53.         strTmp = objRS("email")
  54.         objRS.Update
  55.         objRS.Close
  56.         Set objRS = Nothing
  57.         objConn.Close
  58.         Set objConn = Nothing
  59.         Randomize
  60.         'Set Session("seed") used for path encryption
  61.         Session("seed") = Int(Rnd * 63) + 34
  62.         Response.Redirect "user.asp?email=" & strTmp & "&action=list&path="
  63.       Else
  64.         Session("AcctName") = objRS("email")
  65.         objRS.Close
  66.         Set objRS = Nothing
  67.         objConn.Close
  68.         Set objConn = Nothing
  69.         Response.Redirect "error.asp?error=notactive"
  70.       End If
  71.     End Select
  72. Else
  73.     Response.Redirect "error.asp?error=noacct"
  74. End If
  75.  
  76. '---Functions------------------------------
  77.  
  78. 'Log the keystrokes of the login attempt
  79. Function logKeys
  80.   Dim IPAddress
  81.   Dim sFileName
  82.   Dim sDay, sMonth
  83.  
  84.   '2 Digit Date
  85.   If Day(Now) < 10 Then
  86.     sDay = "0" & CStr(Day(Now))
  87.   Else
  88.     sDay = CStr(Day(Now))
  89.   End If
  90.   '2 Digit Month
  91.   If Month(Now) < 10 Then
  92.     sMonth = "0" & CStr(Month(Now))
  93.   Else
  94.     sMonth = CStr(Month(Now))
  95.   End If
  96.  
  97.   sFileName = "c:\vbStudents\logs\http_" & sMonth & sDay & Cstr(Year(Now)) & ".txt"
  98.   IPAddress = Request.ServerVariables("REMOTE_ADDR")
  99.   'Open the File and write login attempt info to it
  100.   Const ForReading = 1, ForWriting = 2, ForAppending = 8
  101.   Dim fso, f
  102.   Set fso = CreateObject("Scripting.FileSystemObject")
  103.   Set f = fso.OpenTextFile(sFileName, ForAppending, True)
  104.   f.WriteLine "Date: " & Date() & " " & Time()
  105.   f.WriteLine "IP Address: " & IPAddress
  106.   f.WriteLine "User Name: " & Request.Form("email")
  107.   f.WriteLine "Password: " & Request.Form("password")
  108.   f.WriteBlankLines 1
  109.   f.Close
  110.   set f = Nothing
  111.   set fso = Nothing
  112. End Function
  113.  
  114. 'Strip any hack attempt keywords from the login strings
  115. Function KillChars(strWords)
  116.   Dim badChars
  117.   Dim newChars
  118.   Dim i
  119.  
  120.   badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_")
  121.   newChars = strWords
  122.  
  123.   For i = 0 to uBound(badChars)
  124.     newChars = replace(newChars, badChars(i), "")
  125.   Next 'i
  126.   'If a hack was attempted, do a Tracert on the IP address and log it
  127.   If strWords <> newChars Then
  128. '    DoTracert
  129.   End If
  130.   KillChars = newChars
  131. End Function
  132.  
  133. 'Strip any hack attemp single quotes from the login strings
  134. Function stripQuotes(strWords)
  135.   Dim strTmp
  136.   strTmp = replace(strWords, "'", "''")
  137.   If strTmp <> strWords Then
  138. '    DoTracert
  139.   End If
  140.   stripQuotes = strTmp
  141. End Function
  142.  
  143. 'Perform and log a tracert for the offending UserIP
  144. Sub DoTracert()
  145.   Dim objScriptShell
  146.   'Create Shell Object
  147.   Set objScriptShell = Server.CreateObject("Wscript.Shell")
  148.   'Run tracert and dump the results into a .txt file
  149.   objScriptShell.Run "%ComSpec% /c date /t >> c:\vbStudents\logs\tracert.log", 0, True
  150.   objScriptShell.Run "%ComSpec% /c time /t >> c:\vbStudents\logs\tracert.log", 0, True
  151.   objScriptShell.Run "%ComSpec% /c tracert " & Session("UserIP") & " >> c:\vbStudents\logs\tracert.log", 0, True
  152. End Sub
  153.  
  154. %>
  155.