Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2010, 12:57 PM
Registered User
 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare to dates in login script

I am trying to write a simple login script where I list member's User ID, Password and membership expiration date in an if statement. When the member logs in, the script is supposed to check the username and the password and compared the expiration date to today's date.

I can not get it to work. The code is below:

function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
var today = new Date();

if (username=="test" && password=="1111" && today<="January 01, 2011" ) { window.location="index.html"; done=1; }
if (username=="test" && password=="2222" && today<="January 01, 2010" ) { window.location="index.html"; done=1; }
if (done==0) { window.location="error.html"; }
}

Can someone help me format the dates so they will work?
 
Old June 16th, 2010, 03:51 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Have to wonder why you are doing this in JavaScript. It means (a) anybody can see what the username and password are and (b) anybody could simply reset their computer clock to before the expiration time.

But I will hope and assume this is for a "toy" site and you are just experimenting with concepts.
Code:
if (username=="test" && password=="1111" && today.getTime() <= (new Date(2011,0,1)).getTime() ) { window.location="index.html"; done=1; }
if (username=="test" && password=="2222" && today.getTime() <= (new Date(2010,0,1)).getTime() )  ) { window.location="index.html"; done=1; }
I should also point out that "done=1" will never matter, because the browser will immediately jump to "index.html" and done will never get set.
 
Old June 16th, 2010, 05:29 PM
Registered User
 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thank You

You help is much appreciated.

Yes, this WAS for a toy (demo) site but the owner never understood what we were talking about so he wouldn't pay to update it to a secure login after we launched the site. It's worked for 5 years now so it's even harder to get him to spend the money. If he don't care we don't care!





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare two dates lakshmi_annayappa Javascript 1 September 3rd, 2007 08:52 AM
How do I compare 2 dates? Lucy Classic ASP Basics 1 May 3rd, 2005 07:24 PM
Compare dates langer123 Classic ASP Basics 2 April 16th, 2005 08:57 AM
Compare dates [problem]... Varg_88 VB Databases Basics 3 August 20th, 2004 09:55 AM
Compare Dates in JS apd8x Javascript 4 June 16th, 2003 08:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.