<% 'Session Handling Class userSession 'Gets all information of the Employer for easy access Sub getUserInfo sqlQuery = "SELECT * from " & tableName & " WHERE " & fld_uid & "='" & request.Cookies("uid") & "';" UserInfo = objDB.queryDB(sqlQuery) End Sub 'Logs the user in Sub userLogin Set sessionRS = objDB.queryDB("SELECT COUNT(*) FROM " & tableSession & " WHERE sid='" & Session.SessionID & "' AND " & fld_uid & "='" & Request.Form("uid") &"';") If sessionRS(0) = 0 Then objDB.Exec("INSERT INTO session VALUES('" & Session.SessionID & "', '" & Request.Form("uid") &"', '" & Now &"')") Else objDB.Exec("UPDATE " & tableSession & " SET tstamp='" & Now & "' WHERE sid='" & Session.SessionID & "' AND " & fld_uid & "='" & Request.Form("uid") &"';") End If response.Cookies("uid") = Request.Form("uid") response.Cookies("sessionid") = Session.SessionID Session("uid") = Request.Form("uid") Session.Timeout = sessionTime / 60 End Sub 'Logs the user out Sub userLogout objDB.Exec("DELETE FROM " & tableSession & " WHERE sid='" & request.Cookies("sessionid") & "';") response.Cookies("uid") = 0 response.Cookies("sessionid") = 0 Session("uid") = 0 Session.Abandon End Sub 'Informs the user that he has been timedOut Sub informLogout ShowHeader "" msgDisplay "You are not logged in, reLogin", "error", "80" ShowFooter() Response.End End Sub 'Removes old not logged out entries Sub removeOldEntries Set sessionRS = objDB.queryDB("SELECT * FROM " & tableSession) While Not sessionRS.EOF sessionSeconds = DateDiff("s", CDate(sessionRS("tstamp")), CDate(Now)) If sessionSeconds > sessionTime Then objDB.exec("DELETE FROM " & tableSession & " WHERE sid='" & sessionRS("sid") & "';") End If sessionRS.MoveNext Wend End Sub 'Checks whether the user is logged in or not function userLoggedIn() removeOldEntries() loginStatus = 1 Set sessionRS = objDB.queryDB("SELECT * FROM " & tableSession & " WHERE sid='" & Session.SessionID & "' AND " & fld_uid & "='" & Request.Cookies("uid") & "'") If sessionRS.bof AND sessionRS.eof Then Reponse.Write "here" loginStatus = 0 Else sessionSeconds = DateDiff("s", CDate(sessionRS("tstamp")), CDate(Now)) End If If Request.Cookies("uid") = "" OR Request.Cookies("sessionid") = "" OR Session("uid") = "" Then loginStatus = 0 End If If sessionSeconds > sessionTime Then loginStatus = 0 End If If loginStatus = 0 Then userLogout() userLoggedIn = false Else objDB.Exec("UPDATE " & tableSession & " SET tstamp='" & Now & "' WHERE sid='" & request.Cookies("sessionid") & "' AND " & fld_uid & "='" & Request.Cookies("uid") &"';") getUserInfo() userLoggedIn = true End If End function 'Just for adding cookies Sub welcomeLogin(sendTo) %>
please wait, you are being logged in...
<% End Sub End Class Class commonFunctions Function chkEmail(sEmail) Set objRegExp = New RegExp searchStr = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$" objRegExp.Pattern = searchStr objRegExp.IgnoreCase = true chkEmail = objRegExp.Test(sEmail) End Function Function randomPassword Randomize For i = 1 To Int((Rnd * 10) + 6) c = Round(36 * Rnd() - 1/2, 0) If c > 9 Then c = c + 87 Else c = c + 48 End If s = s & Chr(c) Next randomPassword = s End Function End Class Set objCFunc = New commonFunctions Set objSession = New userSession %>