Not sure how else to describe this...
The following function works perfectly when I open the firebug script panel and define breakpoints at relevant lines, but when I don't, the code returns an entirely different result. It seems to be ignoring certain parts of the script when the breakpoints aren't defined, yet I wouldn't know exactly what part is ignored since I have to close the Firebug panel to replicate it. Yes... it's a paradox.
Here's the code, if there's some obvious mistakes that I just don't see, then I guess that may well be the problem.
function authenticate(){
var cookiepass; /*** Valid password hash for the cookie (This uses a unique salt for each user, making it different from the 'truepass' variable.)***/
var truepass; /* Valid password hash. The prompt() reply is compared to this hash.*/
var replyhash; /* Correctly hashed version of the prompt() reply.*/
/* Get contents of the 'access' cookie */
var cookie = readCookie('access');
/* Query PHP script to get the true cookiepass */
$.post("database.php", { pass: cookie, type: 'cookie'},
function(data) {
cookiepass = data;
}
);
if(cookie == cookiepass){
/* If cookie contents matches the true cookiepass, return true. */
return true;
}else{
/* Else, prompt the user for password. */
var reply = prompt('Enter Password:', "");
/* Query database for all three passes, type goes into a switch statement that should go to 'default'. */
$.post("database.php", { pass: reply, type: ''},
function(data) {
/* The passes are separated by '[BRK]' statements: Cookiepass[BRK]Replyhash[BRK]Truepass */
var passes = data.split("[BRK]");
truepass = passes[2];
replyhash = passes[1];
cookiepass = passes[0]
}
);
if(replyhash == truepass){
/* If the hashed form of the reply matches the truepass, set a cookie with the valid cookiepass, then return true.*/
setCookie('access',cookiepass,7);
return true;
}else{
/* If not, alert the user, then return false.*/
alert("Wrong password!")
return false;
}
}
}
The script is supposed to check for a password, even though that's pretty much a useless thing to do client-side. The password is hashed server-side in the database.php file, but I don't have access to an SQL database or the .htaccess file. Therefore, I'm forced to find a PHP-JScript solution to it.
Mainly though, has anyone had the problem before, that a piece of code works when breakpoints are set in Firebug, but not without?
Thanks in advance for any help
Cbeppe.
This post has been edited by Cbeppe: 03 November 2011 - 10:08 AM

New Topic/Question
Reply



MultiQuote




|