Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Possible md5 encrypting error

Possible md5 encrypting error

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphpdatabasemysqlsecurity
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SRJ92
    wrote on last edited by
    #1

    hello, i am hoping someone will be able to help me with this, i have a basic login form using md5 encryption.... Login.php (the form)

    <?php echo '<div id="errors">'.$err.'</div>'; ?><br/>
    <table><tr><td>
    <form method="post" action="login_go.php">Username:
    </td><td>
    <input typ="text" name="user">
    </td></tr><tr><td>
    Password:
    </td><td>
    <input type="password" name="passcode">
    </td></tr><tr><td>
    <input type="submit" value="Log In"></td></tr></table><br/>

    login_go.php (the processing)

    <?php
    session_start();
    Include("connect.php");
    $username = ($_POST['user']);
    $password = md5($_POST['passcode']);
    $q = mysql_query("SELECT * FROM users WHERE user = '$username' AND pass = '$password'") or die (mysql_error());
    $r = mysql_num_rows($q);

    	if ($r == 1) {
    		$\_SESSION\['logged'\] = TRUE;
    		$\_SESSION\['user'\] = $username;
    		$\_SESSION\['email'\] = $email;
    		$\_SESSION\['date'\] = $joined;
    		header("Location: members.php");
    		exit(); // Stops the rest of the script.
    	} else { 
    		 $err.='Incorrect username/password!'; 
    		Include("login.php");
    	}
    

    ?>

    On my database, the password is encrypted correctly but when i come to login i only need to enter the user and i gain access, and when i put a password into it, i then get an error .... what have i done wrong ? ? Thanks Steve

    G 1 Reply Last reply
    0
    • S SRJ92

      hello, i am hoping someone will be able to help me with this, i have a basic login form using md5 encryption.... Login.php (the form)

      <?php echo '<div id="errors">'.$err.'</div>'; ?><br/>
      <table><tr><td>
      <form method="post" action="login_go.php">Username:
      </td><td>
      <input typ="text" name="user">
      </td></tr><tr><td>
      Password:
      </td><td>
      <input type="password" name="passcode">
      </td></tr><tr><td>
      <input type="submit" value="Log In"></td></tr></table><br/>

      login_go.php (the processing)

      <?php
      session_start();
      Include("connect.php");
      $username = ($_POST['user']);
      $password = md5($_POST['passcode']);
      $q = mysql_query("SELECT * FROM users WHERE user = '$username' AND pass = '$password'") or die (mysql_error());
      $r = mysql_num_rows($q);

      	if ($r == 1) {
      		$\_SESSION\['logged'\] = TRUE;
      		$\_SESSION\['user'\] = $username;
      		$\_SESSION\['email'\] = $email;
      		$\_SESSION\['date'\] = $joined;
      		header("Location: members.php");
      		exit(); // Stops the rest of the script.
      	} else { 
      		 $err.='Incorrect username/password!'; 
      		Include("login.php");
      	}
      

      ?>

      On my database, the password is encrypted correctly but when i come to login i only need to enter the user and i gain access, and when i put a password into it, i then get an error .... what have i done wrong ? ? Thanks Steve

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      First, you should really escape the $_POST['user'] value before putting it into an SQL query:

      $username = mysql_real_escape_string($_POST['user']);

      As for why it logs you in when the password is left blank, my guess is that the hashed password is actually the MD5 hash of an empty string. In other words, the correct password is a blank password. SELECT MD5('') gives me d41d8cd98f00b204e9800998ecf8427e - is that what you have?

      S 1 Reply Last reply
      0
      • G Graham Breach

        First, you should really escape the $_POST['user'] value before putting it into an SQL query:

        $username = mysql_real_escape_string($_POST['user']);

        As for why it logs you in when the password is left blank, my guess is that the hashed password is actually the MD5 hash of an empty string. In other words, the correct password is a blank password. SELECT MD5('') gives me d41d8cd98f00b204e9800998ecf8427e - is that what you have?

        S Offline
        S Offline
        SRJ92
        wrote on last edited by
        #3

        yeh actually, i have just took the md5 encrypting off and it inserts nothing into the db and i do get d41d8cd98f00b204e9800998ecf8427e .... how do i fix this ?

        modified on Friday, April 23, 2010 6:19 PM

        S 1 Reply Last reply
        0
        • S SRJ92

          yeh actually, i have just took the md5 encrypting off and it inserts nothing into the db and i do get d41d8cd98f00b204e9800998ecf8427e .... how do i fix this ?

          modified on Friday, April 23, 2010 6:19 PM

          S Offline
          S Offline
          SRJ92
          wrote on last edited by
          #4

          Fixed it , thanks for all your help ...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups