djfenom
06-06-2005, 04:14 PM
I have created a client login page using Dreamweaver and I have tweaked it a bit so that the user gets redirected to a page on an external site where their website is hosted. Here is the code I have used:
<%
' *** 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=""
MM_redirectLoginFailed="index.asp?deny=true"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_clients_STRING
MM_rsUser.Source = "SELECT username, password, website"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM users WHERE username='" & Replace(MM_valUsername,"'","''") &"' AND password='" & Replace(Request.Form("password"),"'","''") & "'"
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("svURL") = MM_rsUser.Fields.Item("website").Value
Session("pass") = MM_rsUser.Fields.Item("password").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 false Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect "http://www." & Session("svURL") & "/clientarea/index.asp?pw=" & Session("pass") & ""
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
<form name="form1" id="form1" method="POST" action="<%=MM_LoginAction%>">
<label for="username">Username:</label>
<input name="username" type="text" id="username" />
<label for="password">Password:</label>
<input name="password" type="password" id="password" />
<label> </label>
<input type="submit" name="Submit" value="Submit" id="submit" />
</form>
This takes the user off to a page such as http://www.website.co.uk/clientarea/index.asp?pw=password. This works fine, but I'm not sure if it's secure enough, I know the session can't be passed from website to website, but is there a better way of doing this? I want it so that nobody can just go straight to http://www.website.co.uk/clientarea and access the pages that way.
Thanks in advance.
Chris
<%
' *** 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=""
MM_redirectLoginFailed="index.asp?deny=true"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_clients_STRING
MM_rsUser.Source = "SELECT username, password, website"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM users WHERE username='" & Replace(MM_valUsername,"'","''") &"' AND password='" & Replace(Request.Form("password"),"'","''") & "'"
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("svURL") = MM_rsUser.Fields.Item("website").Value
Session("pass") = MM_rsUser.Fields.Item("password").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 false Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect "http://www." & Session("svURL") & "/clientarea/index.asp?pw=" & Session("pass") & ""
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
<form name="form1" id="form1" method="POST" action="<%=MM_LoginAction%>">
<label for="username">Username:</label>
<input name="username" type="text" id="username" />
<label for="password">Password:</label>
<input name="password" type="password" id="password" />
<label> </label>
<input type="submit" name="Submit" value="Submit" id="submit" />
</form>
This takes the user off to a page such as http://www.website.co.uk/clientarea/index.asp?pw=password. This works fine, but I'm not sure if it's secure enough, I know the session can't be passed from website to website, but is there a better way of doing this? I want it so that nobody can just go straight to http://www.website.co.uk/clientarea and access the pages that way.
Thanks in advance.
Chris