Link to home
Start Free TrialLog in
Avatar of rgroft
rgroftFlag for United States of America

asked on

Can you have a required log-in password automatically change when a certain date happens?

I would like a login password to automatically change when a certain date rolls around.

Example: the required login password for 28/4/2009 is "password01". On 05/5/2009 the required  password changes to "password02".  I have about 15 passwords total. Is this possible? If so, how?

I have an Input Text box with the var: password. I have an Enter button with the code below attached to it.

//the enter button code
on(release, keyPress"<Enter>") {
		if(password eq "somePassword") {
			gotoAndStop("start");
		} else{
			gotoAndStop("wrong");
			password = "";
		}
}

Open in new window

Avatar of ccarey
ccarey
Flag of Australia image

Assuming your passwords are contained in the actionscript, you could do this (see code snippet)

Note that when setting up the dates, the MONTH component is zero-based, so January is 0, Feb is 1, March is 2 and so on

eg: this element says that the password "pass1" is valid on or after 25th April 2009
{ date: new Date(2009,3,25), pass:"pass1" },


// DEFINE YOUR PASSWORDS AND DATES. Specify in ascending date order
var passwords = [
	{ date: -1, pass:"pass0" }, // impossible date value for 'first' password
	{ date: new Date(2009,3,25), pass:"pass1" },
	{ date: new Date(2009,3,26), pass:"pass2" },
	{ date: new Date(2009,3,27), pass:"pass3" },
	{ date: new Date(2009,3,28), pass:"pass4" },
	{ date: new Date(2009,3,29), pass:"pass5" },
	{ date: new Date(2009,4,1), pass:"pass6" }
]
 
// return the current password for today's date
function getCurrentPassword() {
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
	var currentPass = passwords[0].pass;	
	for(var i=0;i<passwords.length;i++){
		if(passwords[i].date >= today) 
			return currentPass;
		currentPass = passwords[i].pass;
	}
}
 
//the enter button code
function checkPassword(pw) {
	return (getCurrentPassword() == pw)
}
 
 
// check password on the button
btn.onRelease = function(){
	var result = checkPassword('pass4');	// replace "pass4" with user input value
	trace(result);
}

Open in new window

I should add that if you are interested in security it would be better to do a remote procedure call or something similar to do the authentication server-side, but for the purpose of securing for the casual browser this will do fine.

In case it wasn't clear, the "btn.onRelease" function takes the place of your on(Release) code. It could also be placed on the button the same way you had it like so:

on(release, keyPress"<Enter>") {
	var result = checkPassword('pass4'); 
	if(result) {
		gotoAndStop("start");
	} else {
		gotoAndStop("wrong");
		password = "";
	}
}

Open in new window

Avatar of rgroft

ASKER

Hi there!
Thank you for getting back to me on this.
I placed your code in my FLA file but it isn't working. The trace says "false". I am assuming that I am doing something wrong. How can I get you an FLA to look at.

Sorry for being a pain on this.
Thank you in advance
Are you able to upload the FLA somewhere for me to download? I think posting email addresses here is verboten :)

Avatar of rgroft

ASKER

here is a link that will allow you to download my FLA file.

http://files.me.com/randygroft/7ggscs
ASKER CERTIFIED SOLUTION
Avatar of ccarey
ccarey
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgroft

ASKER

Thank you very much!
Your solution was perfect. I'm looking forward to studying it.