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("login"
If login = "login_again" Then
Session("UserLoggedIn"
= ""
ShowLogin
Else
If Session("UserLoggedIn"
= "true" Then
AlreadyLoggedIn
Else
If login = "true" Then
CheckLogin
Else
ShowLogin
End If
End If
End If
Sub ShowLogin
Response.Write(Error_Msg & "<br>"
%>
And the next bit goes within the code for the form on the page.
<table width="85%" border="0" cellspacing="0" cellpadding="0" height="122">
<tr>
<td height="97" align="center">
<form name="form1" method="post" action="newmain.asp">
Existing clients, please type in your <br>
password for your preview area
<input type="password" name="userpwd">
<input type=hidden name=login value=true>
<input type='submit' value='login' name="submit">
</form>
<% End Sub
Sub AlreadyLoggedIn
%>
<%
End Sub
Sub CheckLogin
Dim Conn, cStr, sql, RS, userpwd, URL
userpwd = Request.Form("userpwd"
Set Conn = Server.CreateObject("ADODB.Connection"
cStr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("dbase/users.mdb"
& ";"
Conn.Open(cStr)
sql = "select * from tbLogin where Password = '" & LCase(userpwd) & "'"
Set RS = Conn.Execute(sql)
If RS.BOF And RS.EOF Then
Error_Msg = "Sorry that password doesn't exist, check your spelling and try again"
ShowLogin
Session("UserLoggedIn"
= "true"
Else
Response.Redirect " & RS("URL"
&""
Response.End
End If
End Sub %>
</td>
</tr>
</table>
The really cool bit is;
Response.Redirect " & RS("URL"
&""
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)
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("login"

If login = "login_again" Then
Session("UserLoggedIn"

ShowLogin
Else
If Session("UserLoggedIn"

AlreadyLoggedIn
Else
If login = "true" Then
CheckLogin
Else
ShowLogin
End If
End If
End If
Sub ShowLogin
Response.Write(Error_Msg & "<br>"

%>
And the next bit goes within the code for the form on the page.
<table width="85%" border="0" cellspacing="0" cellpadding="0" height="122">
<tr>
<td height="97" align="center">
<form name="form1" method="post" action="newmain.asp">
Existing clients, please type in your <br>
password for your preview area
<input type="password" name="userpwd">
<input type=hidden name=login value=true>
<input type='submit' value='login' name="submit">
</form>
<% End Sub
Sub AlreadyLoggedIn
%>
<%
End Sub
Sub CheckLogin
Dim Conn, cStr, sql, RS, userpwd, URL
userpwd = Request.Form("userpwd"

Set Conn = Server.CreateObject("ADODB.Connection"

cStr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("dbase/users.mdb"

Conn.Open(cStr)
sql = "select * from tbLogin where Password = '" & LCase(userpwd) & "'"
Set RS = Conn.Execute(sql)
If RS.BOF And RS.EOF Then
Error_Msg = "Sorry that password doesn't exist, check your spelling and try again"
ShowLogin
Session("UserLoggedIn"

Else
Response.Redirect " & RS("URL"

Response.End
End If
End Sub %>
</td>
</tr>
</table>
The really cool bit is;
Response.Redirect " & RS("URL"

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)