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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Today's top tip - redirect user based on password

Status
Not open for further replies.

mlawson

Technical User
Joined
Jun 12, 2001
Messages
197
Location
GB
Hello folks,

While I am twiddling my thumbs ('resting' actors call it) I thought it would be good to pop up another snippet of code that I have often thought 'why can't I find that anywhere?' whilst trawling the forums.
Well here we are, how do you get someone to type in a password (yep, no username, just a password, quite cool for lots of clients) and then pass them to their page? Well after some real deep digging I managed to cobble together some code, the first bit goes under the <%Language-VBScript%> header

<%
Response.Expires = -1000 'Makes the browser not cache this page
Response.Buffer = True 'Buffers the content so our Response.Redirect will work

Dim Error_Msg

login = Request.Form(&quot;login&quot;)
If login = &quot;login_again&quot; Then
Session(&quot;UserLoggedIn&quot;) = &quot;&quot;
ShowLogin
Else
If Session(&quot;UserLoggedIn&quot;) = &quot;true&quot; Then
AlreadyLoggedIn
Else
If login = &quot;true&quot; Then
CheckLogin
Else
ShowLogin
End If
End If
End If

Sub ShowLogin
Response.Write(Error_Msg & &quot;<br>&quot;)
%>

And the next bit goes within the code for the form on the page.

<table width=&quot;85%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;122&quot;>
<tr>
<td height=&quot;97&quot; align=&quot;center&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;newmain.asp&quot;>
Existing clients, please type in your <br>
password for your preview area
<input type=&quot;password&quot; name=&quot;userpwd&quot;>
<input type=hidden name=login value=true>
<input type='submit' value='login' name=&quot;submit&quot;>
</form>
<% End Sub
Sub AlreadyLoggedIn
%>
<%
End Sub

Sub CheckLogin
Dim Conn, cStr, sql, RS, userpwd, URL
userpwd = Request.Form(&quot;userpwd&quot;)
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cStr = &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=&quot; & Server.MapPath(&quot;dbase/users.mdb&quot;) & &quot;;&quot;
Conn.Open(cStr)
sql = &quot;select * from tbLogin where Password = '&quot; & LCase(userpwd) & &quot;'&quot;
Set RS = Conn.Execute(sql)
If RS.BOF And RS.EOF Then
Error_Msg = &quot;Sorry that password doesn't exist, check your spelling and try again&quot;
ShowLogin
Session(&quot;UserLoggedIn&quot;) = &quot;true&quot;
Else
Response.Redirect &quot; & RS(&quot;URL&quot;) &&quot;&quot;
Response.End
End If
End Sub %>
</td>
</tr>
</table>

The really cool bit is;

Response.Redirect &quot; & RS(&quot;URL&quot;) &&quot;&quot;
Response.End

If, in your database you have fields for password, ID and URL, match them up, try it out and unleash it on the world!

Have Fun!

M

(Again, a million sorrys for the length)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top