Forums

This topic is locked

Please remember me!

Posted 23 Sep 2002 12:15:01
1
has voted
23 Sep 2002 12:15:01 Simon Bloodworth posted:
I have a login page which once a user puts the right username and password, they have access to all the pages in that folder. Is it possible to put a cookie on the login page? So when they visit the page again they dont have to type it all in again.

Red Leader

Replies

Replied 23 Sep 2002 14:24:18
23 Sep 2002 14:24:18 Owen Eastwick replied:
Yes,

You should really give the user the option to use a cookie, so put a checkbox after the username and password text boxes that the user has to check in order to use a "remember me" cookie.

<input type="checkbox" name="chkRemember" value="Yes">

Within the login code create the cookie, something like:

<%
If NOT rsUserCheck.BOF OR NOT rsUserCheck.EOF Then
Session("Userneme" = rsUserCheck.Fields.Item("Username".Value

If Request("chkRemeber" = "Yes" Then
Response.Cookies("YourDomain"("Username" = Request("txtUsername"
Response.Cookies("("YourDomain"("Password" = Request("txtPassword"
Response.Cookies("TDSF".Expires = Date + 30 ' set when you want the cookie to expire
End If

End If ' Username found
%>


Modify the Username and Password text boxes to automatically pre-fill with the username and password the nesxt time the user visits, so that they just hit the login button:

<input name="txtUsername" type="text" value="<%= Request.Cookies("YourDomain"("Username" %>">
<input name="txtPassword" type="text" value="<%= Request.Cookies("YourDomain"("Password" %>">

Alternatively you can modify the MX restrict access to page behaviour or write your own so that a page can be viewed if either the cookie or the session variable exists, so that users with a cookie don't have to log in at all:

<%
If Session("Username" = "" AND Request.Cookies("YourDomain"("Username" = "" Then
Response.Redirect("LoginPage.asp"
End If
%>

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 23 Sep 2002 14:26:11
23 Sep 2002 14:26:11 Dave Clarke replied:
there is an extension here

www.basic-ultradev.com/extensions/index.asp?offset=40

that you may find useful
Replied 23 Sep 2002 17:07:32
23 Sep 2002 17:07:32 Simon Bloodworth replied:
ADODB.Fields error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/login.asp, line 57

This is the error I am now getting.

line 57 is

Session("Username" = rs_User.Fields.Item("Username".Value


Any ideas.


Red Leader
Replied 24 Sep 2002 04:50:18
24 Sep 2002 04:50:18 Dave Thomas replied:
the default session is (MM_Username), give that a try, and look at your code to see if there is any difference with naming titles etc..

Regards,
Dave

UD4 || Flash || Access ||Web Hosting
Replied 24 Sep 2002 09:53:50
24 Sep 2002 09:53:50 Simon Bloodworth replied:
I am now getting this error:
ADODB.Fields error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/login.asp, line 57


This is line 57

Session("MM_Username" = rs_User.Fields.Item("MM_Username".Value

Appreciate you help

Red Leader
Replied 24 Sep 2002 11:02:32
24 Sep 2002 11:02:32 Owen Eastwick replied:
The Username field has to be what YOU called it in YOUR database user info table, so:

Session("WhateverYouWantToUse" = rs_User.Fields.Item("WhateverYouCalledTheUsernameFieldInYourDatabaseTable".Value

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 24 Sep 2002 12:23:57
24 Sep 2002 12:23:57 Simon Bloodworth replied:
Not trying to be a complete pain in the arse but I cant seem to get it.

Below is the complete code from my page for login.

Now getting the error:
Microsoft VBScript runtime error '800a01a8'

Object required: 'DB_Password'

/login.asp, line 55

====================

<%
Dim rs_User
Dim rs_User_numRows

Set rs_User = Server.CreateObject("ADODB.Recordset"
rs_User.ActiveConnection = MM_downloads_source_STRING
rs_User.Source = "SELECT * FROM DB_Password"
rs_User.CursorType = 0
rs_User.CursorLocation = 2
rs_User.LockType = 1
rs_User.Open()

rs_User_numRows = 0
%>

<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL"
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("username")
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="secure/default.asp"
MM_redirectLoginFailed="login_no_user.asp"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_downloads_source_STRING
MM_rsUser.Source = "SELECT ID_User, ID_Password"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM DB_Password WHERE ID_User='" & Replace(MM_valUsername,"'","''" &"' AND ID_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
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(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If

If NOT DB_Password.BOF OR NOT DB_Password.EOF Then
Session("Username" = DB_Password.Fields.Item("ID_User".Value

If Request("chkRemember" = "Yes" Then
Response.Cookies("www.ecoflow.ltd.uk")("MM_Username" = Request("username"
Response.Cookies("www.ecoflow.ltd.uk")("password" = Request("password"
Response.Cookies("TDSF".Expires = Date + 30 ' set when you want the cookie to expire
End If

End If ' Username found
%>

<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
rs_User_numRows = rs_User_numRows + Repeat1__numRows
%>

Red Leader
Replied 26 Mar 2008 19:06:12
26 Mar 2008 19:06:12 Diego Alv replied:
My dear friend... don´t complicate, here you have a very easy code for you:

this you´ll put at the top of the .asp page:

'< %
If cstr(Request.Form("txtUsername")<>"" Then
If Request.form("chkRemember" ="1" Then
Response.Cookies("myusername" = Request.Form("txtUsername"
Response.Cookies("mypassword" = Request.Form("txtPassword"
Response.Cookies("rememberme" = "1"
Response.Cookies("myusername".expires = Date + 30
Response.Cookies("mypassword".expires = Date + 30
Response.Cookies("rememberme".expires = Date + 30
Else
Response.Cookies("rememberme" = ""
Response.Cookies("myusername" = ""
Response.Cookies("mypassword" = ""
End If
End If
%>'



and the fields in the form tag should look like:

<p><input value="<%= Request.Cookies("myusername" ) %>" name="txtUsername" id="txtUsername" type="text" /></p>
<p><input value="<%= Request.Cookies("mypassword" ) %>" name="txtPassword" id="txtPassword" type="password" /></p>
<p><input <%If (Request.Cookies("rememberme" ) = "1" ) Then Response.Write("CHECKED" ) : Response.Write("" )%> type="checkbox" name="chkRemember" value="1"> </p>



you should replace this to match your field´s name... you can also download the plugin form dreamweaver mx8 here: www.tom-muck.com/extensions/help/RememberMe/


Reply to this topic