VBScript Help

Hi All,

I'm building a script that runs if a checkbox is checked, however currently it is running regardless of whether the checkbox is checked or not. It also creates secure cookies, from variables, but instead of the variables showing i see the variable names??

Here are the lines of code in question -

		        If NOT IsNull(request("SignInRememberMe")) Then
				Dim ValuetoHash
				ValuetoHash = arrLogin(1,candlogin) & arrLogin(2,candlogin) & arrLogin(3,candlogin)
				Dim HashValue 
				HashValue = sha256(ValuetoHash)
				
				Response.AddHeader "Set-Cookie", "(""cookie"")(""Authentication"")=sha256(ValuetoHash); path=/; HttpOnly" 
				Response.AddHeader "Set-Cookie", "(""cookie"")(""LoggedIn"")=Date; path=/; HttpOnly" 
				Response.Cookies("JobsterUK").Expires = dateAdd("d", 365, Now())		        
		    	end if
				result = 3        		    
			end if

Open in new window


When i view the cookies i get sha256(ValuetoHash) and Date

What am i doing wrong?

Thanks
garethtnashAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
try

 If NOT IsNull(request("SignInRememberMe")) and request("SignInRememberMe") <> "" Then
	Dim ValuetoHash
	ValuetoHash = arrLogin(1,candlogin) & arrLogin(2,candlogin) & arrLogin(3,candlogin)
	Dim HashValue 
	HashValue = sha256(ValuetoHash)
				
	Response.AddHeader "Set-Cookie", "(""cookie"")(""Authentication"")=" & sha256(ValuetoHash) & "; path=/; HttpOnly" 
	Response.AddHeader "Set-Cookie", "(""cookie"")(""LoggedIn"")=" & Date & "; path=/; HttpOnly" 
	Response.Cookies("JobsterUK").Expires = dateAdd("d", 365, Now())		        
	end if
	result = 3        		    
end if

Open in new window

garethtnashAuthor Commented:
Hi Big Monty,

Unfortunately the first part isn't working, now regardless of whether the checkbox is checked or not, the scripts don't run.

The element in the form is

<input type="checkbox" name="rememberme" id="SignInRememberMe" value="true" checked="checked" form="SignIn">

Open in new window


The second part works great, except I'm trying to ensure the cookies remain for 365 days, so the code now looks like

Response.AddHeader "Set-Cookie", "(""Domain"")(""Authentication"")= " & HashValue & "; expires=" & CookieDate & "; domain=www.domain.co.uk; path=/; HttpOnly" 
				Response.AddHeader "Set-Cookie", "(""Domain"")(""LoggedIn"")=" & Date & "; expires=" & CookieDate & "; domain=www. Domain.co.uk; path=/; HttpOnly" 

Open in new window


I have created CookieDate further up in the script as

Dim CookieDate
				CookieDate = dateAdd("d", 365, Now())

Open in new window


When I run this, with the original opening If statement, the cookies get created, as secure HTTPOnly, with the domain name, but no expiry date -> if i close the browser and reopen the cookies are gone?

Help!

Thanks
garethtnashAuthor Commented:
Update, I've got the opening If statement working now,

But

Response.AddHeader "Set-Cookie", "(""Domain"")(""Authentication"")= " & HashValue & "; expires=" & CookieDate & "; domain=www.domain.co.uk; path=/; HttpOnly" 
				Response.AddHeader "Set-Cookie", "(""Domain"")(""LoggedIn"")=" & Date & "; expires=" & CookieDate & "; domain=www. Domain.co.uk; path=/; HttpOnly"

Open in new window


Is not creating any cookies...

Thanks
Big MontyWeb Ninja at largeCommented:
when you do a Request on a form post, you have to use whatever the NAME value is, not what;s stored in the ID attribute, that's why your first IF statement wasn't working...

as for the cookie, what is the value of DATE, highlighted in bold below:

Response.AddHeader "Set-Cookie", "(""Domain"")(""LoggedIn"")=" & Date & "; expires=" & CookieDate & "; domain=www. Domain.co.uk; path=/; HttpOnly"

also, why do you have the double quotes around Domain and LoggedIn?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garethtnashAuthor Commented:
thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.