Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password protection

Status
Not open for further replies.

orlandoj

Programmer
Feb 10, 2003
27
0
0
US
Hi,

I'm relatively new to ASP, so please bear with me! :) I was wondering how I go about password protecting some admin pages on my site. For example, when they try to load the page, it pops up "please enter the password..." and then you are either granted or denied access.

Hopefully a simple question...

Thanks,
-Jamie
 
You cant have a popup in ASP requesting a password before loading the page.
What you can do is create a login page then on the restricted pages check if the user is logged in.
If you need more help just ask... Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Here is a script that I'm currently using that works very well. It uses and Access table which contains the name passwords and IP addresses of everyone that will be accessing your site. You can specify where a persons can gain access by assigning them an IP address to a webpage. Check it out. All you have to do is create a table with the same names I have in bold, setup a DSN, copy and past this code into a page and your in business.

<%
'HERE IS THE CODE TO THE FORM:


Option Explicit
Dim strError, strSQL, objRS
'see if the form has been submitted
If Request.Form(&quot;action&quot;)=&quot;login&quot; Then
'the form has been submitted

'// validate the form

'check if a username has been entered
If Request.Form(&quot;username&quot;) = &quot;&quot; Then _
strError = strError & &quot;- Please enter a username<br>&quot; & vbNewLine

'check if a password has been entered
If Request.Form(&quot;password&quot;) = &quot;&quot; Then _
strError = strError & &quot;- Please enter a password<br>&quot; & vbNewLine

'// check if an error has occured
If strError = &quot;&quot; Then
'continue
'include database connection code
%>
<%
Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
'Set Rlog = Server.CreateObject (&quot;ADODB.Recordset&quot;)
Set oRS = Server.CreateObject (&quot;ADODB.Recordset&quot;)
objConn.Open &quot;ASPVOL&quot;

'-- Declare your variables
Dim Cnt, cmdDC, RecordSet, oRS, bDate, eDate, objConn
'-- Create object and open database
Set cmdDC = Server.CreateObject(&quot;ADODB.Command&quot;)
cmdDC.ActiveConnection = objConn
%>
<%

'// create the SQL
strSQL = &quot;SELECT RecordId,pass,address FROM StarAdmin WHERE Supervisors='&quot; & _
fixQuotes(Request.Form(&quot;username&quot;)) & &quot;'&quot;


'// run the SQL
Set objRS = objConn.Execute (strSQL)
'// see if there are any records returned
If objRS.EOF Then
'no username found
strError = &quot;- Invalid username or password<br>&quot; & vbNewLine
Else
'check password
If objRS(&quot;pass&quot;)=Request.Form(&quot;password&quot;) Then
'username/password valid
'save session data
Session(&quot;loggedin&quot;) = True
Session(&quot;userid&quot;) = objRS(&quot;RecordId&quot;)
'redirect to members area
Response.Redirect (objRS(&quot;address&quot;))
Response.End
Else
'invalid password
strError = &quot;- Invalid username or password<br>&quot; & vbNewLine
End If
End If

End If
If strError <> &quot;&quot; Then
'output the error message
'add extra HTML...
strError = &quot;<p><font color=&quot;&quot;#FF0000&quot;&quot;>The following errors occured:&quot; & _
&quot;</font><br>&quot; & vbNewLine & strError
End If
'display message in URL.. (ie thank you for registering)
If Request.QueryString(&quot;msg&quot;) <> &quot;&quot; And strError = &quot;&quot; Then
strError = &quot;<p>&quot; & Request.QueryString(&quot;msg&quot;) & &quot;</p>&quot;
End If
End If

Function fixQuotes(strData)
fixQuotes = Replace(strData,&quot;'&quot;,&quot;''&quot;)
End Function

're-set session data (ie log out)
Session(&quot;loggedin&quot;)=&quot;&quot;
Session(&quot;userid&quot;)=&quot;&quot;
%>
<html>
<head>
<title>Members Area Login</title>
</head>
<body>
<h1 align=&quot;center&quot;>
<img border=&quot;0&quot; src=&quot;Report1.jpg&quot; width=&quot;170&quot; height=&quot;164&quot;></h1>
<p align=&quot;center&quot;>Please enter your username and password to this portion of the
site.</p>
<%=strError%>
<form action=&quot;ANewlogin.asp&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;login&quot;>
<div align=&quot;center&quot;>
<center>
<table border=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td><b>Username:  </b></td>
<td>
<input type=&quot;text&quot; maxlength=20 name=&quot;username&quot;
value=&quot;<%=Server.HTMLEncode(Request.Form(&quot;username&quot;))%>&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td><b>Password:  </b></td>
<td>
<input type=&quot;password&quot; maxlength=20 name=&quot;password&quot;
value=&quot;<%=Server.HTMLEncode(Request.Form(&quot;password&quot;))%>&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td> </td>
<td><input type=&quot;submit&quot; value=&quot;Login&quot;></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
<%

Set cmdDC = Nothing
Set Cnt = Nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top