Jump to content

Recommended Posts

I'm writing a simple password protected file. The catch is that I only want one php file and I wanted to know if this is secure. If $thepassword is commented out it should skip the password and go straight to the content. Would it be better to somehow encrypt the password using md5?

 

$thepassword = "pwgoeshere";

if(!$password && $thepassword != null){
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
echo "<head><title>Please enter your password</title>\n";
echo "<link href=\"$css\" rel=\"stylesheet\" type=\"text/css\" />\n";
echo "</head>\n<body>\n";
echo "<form method=\"post\" id=\"pwform\" action=\"".$_SERVER["PHP_SELF"]."\">\n";
echo "<p><input type=\"password\" name=\"password\" id=\"password\" /></p></form>\n";
echo "</body></html>";

die();
}

if($password == $thepassword || $thepassword == null) {

Secure content

} else {
//The wrong password was entered or something wrong happened.
//This will forward you back to the password entry page.
header("Location: ".$_SERVER['PHP_SELF']."");
}

Link to comment
https://forums.phpfreaks.com/topic/62906-is-this-secure/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.