Help - Authentication with ASP

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Lorenzo (NO_SPAMmargola_at_it2b.it.)
Date: 05/05/04


Date: Wed, 5 May 2004 15:57:26 +0200

I had to transfer an ASP Web Application (developed by another person) to a
different web server. It seems to work but not completely.

I have some problems with authentication: it is based on a username and a
password stored in a SQL Server's table. These data are requested via basic
authentication (not a IIS level but I think it is used to create the
authentication window in which put username and password). The problem is
that it doesn't accept username and password and, after three times, it
redirect me to a page telling "You don't have rights to see this page". What
could I do?

Thanks a lot
Lorenzo
Here's the code:
<%
Dim attivo
attivo = 0

SET UUEncode = Server.CreateObject( "Scripting.Dictionary" )
FOR i=0 TO 63
 SELECT CASE i
  CASE 0 offset = 65
  CASE 26 offset = 71
  CASE 52 offset = -4
 END SELECT
 UUEncode( CHR( i + offset) ) = i
NEXT

Function Decode ( TheString )
 For byteGroup = 1 To Len( theString ) Step 4
  numBytes = 3
  groupBytes = 0
  For CharCounter = 0 to 3
   thisChar = Mid( theString, byteGroup + CharCounter, 1)
   If thisChar = "=" Then
    numBytes = numBytes - 1
    thisByte = 0
   Else
    thisByte = UUEncode( thisChar )
   End If
   groupBytes = 64 * groupBytes + thisByte
  Next

  For k = 1 To numBytes
   Select Case k
    CASE 1: thisChar = groupBytes \ 65536
    CASE 2: thisChar = (groupBytes And 65535) \ 256
    CASE 3: thisChar = (groupBytes And 255)
   End Select
   Decode = Decode & Chr( thisChar )
  Next
 Next
End Function

auth = TRIM(Request.ServerVariables("HTTP_AUTHORIZATION"))
IF auth = "" THEN
 Response.Status = "401 Not Authorized"
 Response.AddHeader "WWW-Authenticate", "Basic realm=""localhost"""
 Response.End
END IF

auth = TRIM( MID( auth, 6) )
auth = Decode( auth )
authSplit = SPLIT( auth, ":" )
username = authSplit( 0 )
password = authSplit( 1 )

Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString=CONNECTION
objConn.Open
sqlString = "SELECT username, password, codice_utente FROM " & user
&"a_dati_utente WHERE username ='" & username & "' AND password='" &
password & "'"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open sqlString, objConn

IF RS.EOF THEN
Response.Status = "401 Not Authorized"
Response.AddHeader "WWW-Authenticate", "Basic realm=""localhost"""
RS.Close
Set RS = Nothing
objConn.Close
Set objConn = Nothing
Response.End
END IF

dim id_utente, id_periodico, id_numero, scaricato, codice_utente,
checkLogin, us, pwd

checkLogin = False

us = TRIM(RS("username"))
psw = TRIM(RS("password"))

if (username=us And password=psw) then
 checkLogin = True
End If

If (checkLogin = False) Then
Response.Status = "401 Not Authorized" 'nessun record trovato
Response.AddHeader "WWW-Authenticate", "Basic realm=""localhost"""
RS.Close
Set RS = Nothing
objConn.Close
Set objConn = Nothing
Response.End
End If

codice_utente = rs("codice_utente")

RS.Close
Set RS = Nothing
objConn.Close
Set objConn = Nothing

%>



Relevant Pages

  • Re: Sending Emal2SMS
    ... you want to know what type of AUTH is supported. ... After you receive the response to the EHLO command you will need to ... EHLO response will tell you what the smtp server accepts. ... To get the long string that contains your username and password you can ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Win2003 IAS CRPs attribute manipulations == MS-CHAPv2 login failures.
    ... The computation of the Peer-Challenge uses the username as one of its ... This would explain why the MYDOMAIN\ find/replace set works, ... AUTH cannot validate the peer ... On PROXY create a remote server group that points to AUTH ...
    (microsoft.public.internet.radius)
  • Re: Urllib2 / add_password method
    ... Don't use a password manager with proxy auth in 2.4, ... Specifying username and password make sense, ... but I haven't found documentation on what 'realm' and 'host' are for. ... I notice just now that urllib2's digest auth support breaks ...
    (comp.lang.python)
  • Problem Understanding Code in 2nd edition Welling/Thomson PHP?MySQL Web Development Book
    ... Sorry for the long post--and the cross-posting to a MySQL list, ... So I went into MySQL and created the database auth and the table auth, ... I used my username that I log into the computer I'm working on--an ... echo 'Cannot connect to database.'; ...
    (php.general)