Hi all,
I am desperate, i just finished coding and implementing a cookie based authentication script in my file upload script. It all works perfectly, but i must have an option that the user can turn the password protection ON or OFF. It works fine ON, but now does not work at all when it is OFF.
The following code is what could turn it off, but I think it is because i have 2 OPEN: "{" in the IF statement. (if u can understand that, lol)
<?
if($auth_ReqPass == "yes")
{
if(isset($fum_user) && !isset($relogin)) {
if(authDo($fum_user, $fum_pass)) {
}
?>
...html code to display if logged in..., and normal code to display if password-protect if OFF
I will try to explain the whole password code as best as I can.
Here is the main password function at the top:
function authDo($auth_userToCheck, $auth_passToCheck) {
$auth_usern = "foo";
$auth_passw = "bar";
$auth_encodedPass = md5($auth_passw);
if ($auth_userToCheck == $auth_usern && $auth_passToCheck == $auth_encodedPass) {
$auth_check = TRUE;
} else {
$auth_check = FALSE;
}
return $auth_check;
}
if (isset($relogin)) {
setcookie ('fum_user', "",time()-3600);
setcookie ('fum_pass', "",time()-3600);
}
if (isset($login)) {
$auth_password_en = md5($auth_formPass);
$auth_username_en = $auth_formUser;
if (authDo($auth_username_en, $auth_password_en)) {
setcookie ('fum_user', $auth_username_en,time()+3600);
setcookie ('fum_pass', $auth_password_en,time()+3600);
$auth_msg = "<b>Authentication successful!</b> The cookies have been set.<br><br>".
$auth_msg . "Your password (MD5 encrypted) is: $auth_password_en";
} else {
$auth_msg = "<b>Authentication error!</b>";
}
}
Ok, then, we call the function at the beginning of the HTML body, to execute the file upload script if the password protection is disabled, or stop the file upload script if password protection is enabled...
<center>
<?
if($auth_ReqPass == "yes")
{
if(isset($fum_user) && !isset($relogin)) {
if(authDo($fum_user, $fum_pass)) {
}
?>
<table width="560".....>
Now, at the END of the file upload script, we have code that will display the login box if the user is not logged in, and 2 end if "}" 's to control the code that is displayed when pass-protection is turned on. But that is now affecting the script when it is turned off...
<?
if($auth_ReqPass == "yes")
{
} else {
echo("<p>Authentication error from cookie values</p>" .
"<p><a href='$_SERVER[PHP_SELF]?relogin=1'>Delete cookies and force login<a></p>");
}
} else {
if (!isset($login) || isset($relogin)) {
?>
<font size="3"><b><i><? echo ($title) ? ($title) : ("File Upload Manager"); ?></i> - Authentication</b></font><br>
<form action="<?=$_SERVER[PHP_SELF]?>?login=1" method="POST"><p>
Username: <input type="text" name="auth_formUser" size="20"><br>
Password: <input type="password" name="auth_formPass" size="20">
<p><input type="submit" name="submit" class="button" value="Log-In"></p>
</form>
<?
} elseif (isset($login)) {
echo("<p>$auth_msg</p>" . "<p>You'll be redirected in 2 seconds!</p>");
}
}
}
?>
test text AFTER end of }
</body>
I hope someone will be able to help me. I just need a way to control the password script if a user turns off the password protection.
Is there a work-around to this? Or turning that bit of code on or off by a variable?
For any help or pointers, I will GREATLY APPRECIATE it!!!
Thankyou very much in advance.
ThePeak