Link to home
Start Free TrialLog in
Avatar of awinstead
awinsteadFlag for United States of America

asked on

User Authentication Restricts everything

Hello everyone,
I have a simple login page that queries an Access database for username and password and access level. We have been using this login system for two years and it has been working like a champ. We have numerious pages that are using the Authenitcation to restric some users from having access to certain areas that only key members should have access to. They all work just fine. Today I went to create a new form and supply basic authentication to the form  and when I load the page it blocks the page for everyone and redirects to the login page. So I took another page that already had authentication (that works fine) and cut and pasted the authentication to the new page instead of using the wizard and I get the exact same thing. Can someone look at the code and tell me what I am doing wrong?

Jester

I did add a couple session variables to the login some time ago
::::::::::::::: Login Page - Login Piece :::::::::::::::::::

<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername=CStr(Request.Form("username"))
If MM_valUsername <> "" Then
  MM_fldUserAuthorization="PositionCode"
  MM_redirectLoginSuccess="reglogin.asp"
  MM_redirectLoginFailed="login_failed.asp"
  MM_flag="ADODB.Recordset"
  set MM_rsUser = Server.CreateObject(MM_flag)
  MM_rsUser.ActiveConnection = MM_Main_DB_STRING
  MM_rsUser.Source = "SELECT Username, password, SREP_CODE, OfficeLocation"
  If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  MM_rsUser.Source = MM_rsUser.Source & " FROM Fullemployees WHERE Username='" & Replace(MM_valUsername,"'","''") &"' AND password='" & Replace(Request.Form("pwd"),"'","''") & "'"
  MM_rsUser.CursorType = 0
  MM_rsUser.CursorLocation = 2
  MM_rsUser.LockType = 3
  MM_rsUser.Open
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
       ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
      Session("MM_SREP_CODE") = (MM_rsUser.Fields.Item("SREP_CODE").Value)
      Session("MM_STORE") = (MM_rsUser.Fields.Item("OfficeLocation").Value)
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And true Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%>


:::::::::::::::: Form Page  - Restriction piece :::::::::::::::::::::
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="1,2,3,4,5,6,7,8"
MM_authFailedURL="../login2.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>

Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

The code seems okay, however, DW's attempts at writing this stuff is pretty hard to read.  Double check that on your form page, the username and password field are NAMEd as "username" & "pwd".

Also check that browser/firewall etc are not blocking cookies.
Avatar of awinstead

ASKER

I checked the login page and I names are labeled "username" and "pwd" The funny thing is if I create a blank page and use the Authentication I get the same problem. There are numerous pages that were created some time ago and they all work just fine. It's just the new pages. I also tried copying and pasting from one of the old pages that work and that one fails too. I am completely baffled on this one. PLease help I am under a tight deadline.

Thanks,
Jester
ASKER CERTIFIED SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial