• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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

0
rgroft
Asked:
rgroft
  • 4
  • 3
1 Solution
 
ccareyCommented:
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

0
 
ccareyCommented:
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

0
 
rgroftAuthor Commented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ccareyCommented:
Are you able to upload the FLA somewhere for me to download? I think posting email addresses here is verboten :)

0
 
rgroftAuthor Commented:
here is a link that will allow you to download my FLA file.

http://files.me.com/randygroft/7ggscs
0
 
ccareyCommented:
The correct password for today (in my timezone at least) is 'pass5' since today is the 29th

Change the code on the button to this so it uses your own text field for the password.

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

and replace the code on the first frame with the code snippet below (found a little error). I tested this and it appears to work fine
stop();
 
// 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) {
					currentPass = passwords[i].pass;   
				}else  {
					return currentPass;
				}
                
        }
}
 
//the enter button code
function checkPassword(pw) {
	trace(getCurrentPassword())
        return (getCurrentPassword() == pw)
}
 
 
//check password on the button
//btn.onRelease = function(){
//     var result = checkPassword('pass4');    // replace "pass4" with user input value
//       if(result) {
//                gotoAndStop("start");
//        } else {
//                gotoAndStop("wrong");
//                password = ""; 
//				trace(result);
//}
//}

Open in new window

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now