Jump to content

PHP not fully running


fredted40x

Recommended Posts

Hi,

 

Im trying to create a really simple password protected page that is fairly secure but when the user doesnt enter a password the wrong error is displayed. Can anyone see a problem?

 

Also could someone please check that im properly compairing the hash password of 2135fa0dd7fb99d167b420b7ff34ec98

with what the user entered when its hashed?

 

login.php

 

<?php
  session_start();
?>
<?php
  $submit = $_POST['submit'];
  $password = md5($_POST['password']);
  if ($submit)
  {

    if ($password)
    {
      if ($password == '2135fa0dd7fb99d167b420b7ff34ec98')
        {
          $_SESSION['user'] = logged;
          header('Location: page.php'); 
        }
        else
        {
	  header('Location: index.php?id=1');
        }
    }
    else
    {
      header('Location: index.php?id=2');
    }
  }
  else
  {
  header('Location: index.php?id=1');
  }
?>

 

index.php

<?php
  $id=$_REQUEST['id'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    <title>Keys</title>
    <link rel = "stylesheet"
          type = "text/css"
          href = "css/layout.css" />
  </head>

  <body>


      <div id="header">
        <h1>Keys</h1>
      </div>

  
      <div id="secondheader">
    
      </div>

  
      <div id="main">
    <form method="POST" action="login.php">
          Password: <input type="password" name="password" onfocus="selected(this)" onblur="notselected(this)">
          <input type="submit" name="submit" value="Login">
        </form>
	<br/>
	<?php
          if ($id==1)
	  {
	    echo "Invalid password. Please try again";
	  }
	  elseif ($id==2)
	  {
	    echo "Please enter a password";
	  }
        ?>

      </div>	

  
      <div id="footer">
        
      </div>
  
      <div id="left">
    
      </div>


  </body> 
</html> 

 

Thanks in advance.

Link to comment
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.