Jump to content

[SOLVED] md5 password help


wargolchaos

Recommended Posts

My script works without the md5 but not with the md5.

 

I cant figure out what im doing wrong. Its driving me crazy.. Please help.

 

Heres my sql.

CREATE TABLE `users` (
  `id` int(10) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL,
  `password` varchar(32) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

Heres how I added a single user to test the database.

<?php
mysql_connect("localhost", "----", "----") or die(mysql_error()); 
mysql_select_db("-------") or die(mysql_error());

$username = 'testuser';
$password = 'testpass';

mysql_query("INSERT INTO test (username, password) VALUES('". mysql_escape_string($username) ."', '".md5($password)."' ) ") or die(mysql_error()); 

?>

 

And here is my login script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>

<div id="wrap">

	<?php 

	mysql_connect("localhost", "-----", "-----") or die(mysql_error());
	mysql_select_db("--------") or die(mysql_error());

	if(isset($_POST['username']) && isset($_POST['password'])){
		// Verify
		$username = mysql_escape_string($_POST['username']);
		$password = $_POST['password'];

		$gUser = mysql_query("SELECT * FROM test WHERE username='".$username."' AND password='".$password."' LIMIT 1") or die(mysql_error());
		$verify = mysql_num_rows($gUser);

		if($verify > 0){
			echo '<h2>Login Complete</h2>
			      <p>Thanks for logging in!</p>';
		}else{
			echo '<h2>Login Failed</h2>
			      <p>Sorry your login credentials are incorrect.';
		}
	}else{
	?>
	<h2>Login</h2>
	<p>Please enter your login credentials to get access to the download area</p>

	<form method="post" action="">
		<fieldset>
			<label for="username">Username:</label><input type="text" name="username" value="" />
			<label for="password">Password:</label><input type="text" name="password" value="" />
			<input type="submit" value="Login" />
		</fieldset>
	</form>

	<?php
	}
	?>
	   
</div>

</body>
</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/170868-solved-md5-password-help/
Share on other sites

you have to MD5 the posted password also. A normal password will never equal its MD5'ed counter part

 

so

 

$gUser = mysql_query("SELECT * FROM test WHERE username='".$username."' AND password='".md5($password)."' LIMIT 1") or die(mysql_error());

 

should fix your problem

 

EDIT: dam ignace beat me to the punch

  Quote

EDIT: dam ignace beat me to the punch

 

HAHA seems like we all are very competitive and eager to show off our skills ;) The whole fun part about this virtual competition is that only the OP is actually gaining something from this :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.