Jump to content

Comparing MD5 Hashes


havox

Recommended Posts

+-----------+----------------------------------+

| username | password                              |

+-----------+----------------------------------+

| user        | Hash                                    |

+-----------+----------------------------------+

 

This is what I have set up in my database(obviously I'm not going to put the real user or hash). I'm trying to md5 what the user inputs for a password and compare it to the database, but I keep getting failed login attempts.

 

<?php
error_reporting(-1);
ini_set('display_errors', 1);

$host = "localhost";  
$dbuser = "****";   
$pass = "****"; 
$databasename = "login";  

mysql_connect($host,$dbuser,$pass)or die('Could not connect: '.mysql_error());  
mysql_select_db($databasename) or die(mysql_error()); 

if (isset($_POST["user"]) && isset($_POST["pwd"])) {
$admin = mysql_query("SELECT username FROM members");
$pass = mysql_query("SELECT password FROM members");
	if ($_POST["user"] == $admin && md5($_POST["pwd"]) == $pass) {
		session_register("admin");
     		session_register("pass");
     		header('Location:https://deadnode.com/output.php'); }
else {
     	echo"<center><h1>Failed login attempt.</h1></center>"; }
}
?>

Link to comment
Share on other sites

mysql_query() returns a result resource, not the data value. I recommend reading a basic php/mysql tutorial to learn how to execute a query and fetch the data from the result resource.

 

Also, session_register(), session_is_registered(), and session_unregister() were depreciated more than 8 years ago in favor of using the $_SESSION array. There are examples of how to use the $_SESSION array in the php.net documentation under Sessions.

 

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.