CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Login Cookie

Print topic Send  topic

Author Message
tecolotemx
Posted: 06/16/2005, 3:27 PM

:*)Hello.

I´m trying to create a sample Login Form than can build a cookie, store the user name, or ID, and then the user don´t need to re-login.
I´m lost in the CCS Events. Where can I add a event to create a Cookie in the Login, and how I do this?

I know that a normal cookie is created like these:
<%
Response.Cookies("username") = "jason"
Response.Cookies("username").Expires = #December 25,2006#
%>
CCS do something like this:
Response.Cookies("login") = Login.login.Value

I wish to recover the CCGetUserID and/or the CCGetUserLogin

help please !!!!
smalloy

Posts: 107
Posted: 06/17/2005, 6:46 AM

Here's an example from working code:

'Login @7-AA430BB1  
    With Login  
        If NOT CCLoginUser(.login.Value, .password.Value) Then  
            .Errors.addError("Login or Password is incorrect.")  
            Login_Button_DoLogin_OnClick = False  
            .password.Value = ""  
        Else  
            If Not IsEmpty(CCGetParam("ret_link", Empty)) Then _  
                Redirect = CCGetParam("ret_link", Empty)  
				Call CaptureHistory  
            Login_Button_DoLogin_OnClick = True  
	  
		' On successful login, persist cookies by giving them an Expires value   
			If Login.RememberMe.Value Then  
				Dim dteDate   
				 dteDate = Date + 31 ' 31 days from today  
					Response.Cookies("login").Expires = dteDate   
					Response.Cookies("pass").Expires = dteDate   
					'Response.Cookies("login").Secure = True   
				' Save login info in cookies   
					Response.Cookies("login") = Login.login.Value   
					Response.Cookies("pass") = Login.password.Value   
				Else   
					Response.Cookies("login") = ""   
					Response.Cookies("pass") = ""   
				End If   
	        End If  
    End With  
'End Login

_________________
Anything can be done, just give me time and money.
View profile  Send private message
tecolotemx
Posted: 06/17/2005, 6:55 AM

Oh Wow !!!!
Thanks a lot.
tecolotemx
Posted: 06/17/2005, 1:50 PM

Thanks for the clues smalloy.

Well, finally i finished my own working example, but it isn´t as easy as I thought.

Here is the complete solution.

1- Edit the "Login" Code.
As Smalloy show, you need to edit the "Login" Pre-defined code.
Add an "if" at the end of the code: "if Login_Button_DoLogin_OnClick = True " to simplify the code.
This code really save a "cookie". You can later retrive the values of the user and the pass.

  
'Login @206-1CDA24EE  
    With Login  
        If NOT CCLoginUser(.login.Value, .password.Value) Then  
            .Errors.addError("Login o Password incorrecto.")  
            Login_Button_DoLogin_OnClick = False  
         	.password.Value = ""  
			  
        Else  
        If Not IsEmpty(CCGetParam("ret_link",Empty)) Then _  
                Redirect = CCGetParam("ret_link",Empty)		  
	       		'  If Not IsEmpty(CCGetParam("ret_link", Empty)) Then _  
              	'   Redirect = CCGetParam("ret_link", Empty)			  
            Login_Button_DoLogin_OnClick = True  
			  
       ' On successful login, persist cookies by giving them an Expires value     
			    
		 	if Login_Button_DoLogin_OnClick = True Then  
			 		Dim dteDate     
				  	dteDate = Date + 31 ' 31 days from today    
					' Save login info in cookies     
					Response.Cookies("log") = Login.login.Value    
					Response.Cookies("log").Expires = dteDate   
					Response.Cookies("pass")= Login.password.Value     
					Response.Cookies("pass").Expires = dteDate  
		  
				 '	Else     
				  
			 	End If     
	        End If    
    End With    
  
'End Login  

2- Verify the cookie content.
Create a sample "Asp" with the following code for check the content of the cookie. Obviusly you need to Login first, and then use this code:

Cookie_reader.asp
  
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>  
<title>Cookie Reader</title>  
</head>  
<body>  
Read the cookie   
<%  
logon = Request.Cookies("log")  
response.write("log: " & logon)  
passw =Request.Cookies("pass")  
response.write("passw: " & passw)  
  
%>  
</body>  
</html>  

3- Adding the values of the cookie into Labels.
Now, we´ll go to save the cookie values into two different new labels.
In my example, i created the labels {userlabel} and {passlabel}

Now we need to add a "Before Show" event for each one.
Go to code and add the following code:

  
'Custom Code @215-73254650  
' -------------------------  
' Write your own code here.  
Dim logon  
	logon = Request.Cookies("log")  
	userlabel.Value = logon  
 ' -------------------------  
'End Custom Code  

  
'Custom Code @216-73254650  
' -------------------------  
' Write your own code here.  
Dim passw  
	passw = Request.Cookies("pass")  
	passlabel.Value = passw	  
  
' -------------------------  
'End Custom Code  

4- Finally, Add "Login" Event into a Label.
The last step is really easy.
We need to select one of the labels, Select a "Before ShoW", then "Add Action" and choose "Login".

In the example, I choosed the -passlabel- Label for the code
  
'Login @220-CF5D354B  
    With passlabel  
        If NOT CCLoginUser(userlabel.Value, passlabel.Value) Then  
            .Errors.addError(" Login or Password is incorrect.")    
            passlabel_BeforeShow = False  
            passlabel.Value = ""  
			End If  
    End With  
'End Login  


Notice that CCS says .userlabel.Value and .passlabel.Value, so just remove the damn "." at the beginning of the words.

Now, It should work.

Add a sample label anywhere for the hello Message. (Called hello)

  
'Custom Code @211-73254650  
' -------------------------  
	 If CCGetUserLogin <>"" Then  
	 'If CCLoginUser(userlabel.Value, passlabel.Value) Then  
  	hello.Value = "Hello: " & CCGetUserLogin  
	Else  
 	hello.Value = ""  
 	End If  
' -------------------------  
'End Custom Code  

Prasanta
Posted: 09/09/2005, 12:52 AM

Hi,
i m a novice in this code field. However i wrote three different codes named as"Form.htm" for login window, "vdateuser.asp" for validating the user. From here i want to navigate to a new window, where i must retrive the username of the validated user and then use that one for database operations. plz tell how to retrive the username value to a variable. my codes are as below:

<html>
<head>
<title>validate usernames and passwords with ASP, MS Access and cookies</title>
<body onload="document.form.username.focus();">
<form name="myform" action="vdateUsr.asp" method="post">
<p align="center"><img border="0" src="../keys.JPG" width="68" height="58">
<p><b><font face="Arial" color="#0000FF">Please Enter your Username &
Password to login into the protected area of PHCPL's eServer</font></b></p>
<p><b><font color="#0000FF">
Username:</font></b> <input name="username" type="text" size="20" maxlength="20" tabindex="1" /><br />

<b><font color="#0000FF">

Password: </font>  </b><input name="password" type="password" size="20" maxlength="20" tabindex="2" /><br />
   
<input name="submit" type="submit" value="Login" />
</p>
</form>
</body>
</html>

****************************************

*****vdateuser.asp**********

<%@Language=VBScript%>

<%
Option Explicit
%>

<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!-- #include file="Connectionstring.asp" -->


<%

' variables
dim cnStr
dim rcSet
dim frmUsername
dim frmPassword
dim sqlStr

'store form input into variables
frmUsername = Request.Form("username")
frmPassword = Request.Form("password")

'create connection and recordset objects
Set cnStr = Server.CreateObject("ADODB.Connection")
Set rcSet = Server.CreateObject("ADODB.Recordset")

' defining database connection (connectionstring.asp)
cnStr.ConnectionString = path
cnStr.Provider = provider
cnStr.open

' execute sql and open as recordset
sqlStr = "Select * From EMPLOYEE where username = '" _
& Request.Form("username") & "' and password = '" & Request.Form("password") & "'"

' Opens the returned values from the SQL as a recordset, ready for iteration by ASP
set rcSet = cnStr.Execute(sqlStr)

' validate variables against database
If (not rcSet.BOF) and (not rcSet.EOF) then
response.cookies("validated_user") = frmUsername
response.cookies("validated_user").expires=dateadd("m", 1, Now)
response.write "<b>Login successful!</b>"
response.write "<p>Welcome " & rcSet.fields(4) &" "& rcSet.fields(5) &" </p>"
response.write "<p>Please select any one from the following</p>"
else
response.write "<b>incorrect username and/or password</b>"
end if
%>

<HTML>
<script language=javascript>

<!--
function OpenURL( Index )
{
if( Index == 0 ) window.location = "http://spje_tai/viewstatus.asp";
if( Index == 1 ) window.location = "http://spje_tai/applyTA.asp";
if( Index == 2 ) window.location = "http://spje_tai/applyMedical.asp";
if( Index == 3 ) window.location = "http://spje_tai/applyfurniture.asp";
}

//-->
</SCRIPT>

<FORM NAME=NAVIGATE>
<SELECT NAME=LIST SIZE=1 OnChange="OpenURL( document.NAVIGATE.LIST.selectedIndex )">
<OPTION NAME=status> The Claim Status page
<OPTION NAME=TA> Apply TA
<OPTION NAME=Medical> Apply medical
<OPTION NAME=Furniture> Apply Furniture
</SELECT>

</FORM>
</HTML>

From here on i am being navigated to a different page. But the value of username is not being retrived for further operations.

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.