Jump to content

Help with md5


mat3000000

Recommended Posts

This code was working until I tried to protect it with md5, What am I doing wrong? Do I need to change my DB table or is it the php?

 

<?php  
session_start();

if (isset($_SESSION['rest']) || isset($_SESSION['chef'])){header('Location: index.php');}

$username = $_POST['username'];
$password = $_POST['password'];

$errors = array();

if($username == 'User Name' || $username == ''){
  $errors[] = 'Please enter a valid username';
}

if($password == 'Password' || $password == ''){
  $errors[] = 'Please enter a valid password';
}

$link = mysql_connect("*****","****","*******") or die ("Could not connect!");
mysql_select_db("*****");


$query = "SELECT * FROM `users` WHERE `username`='$username' AND `password`='".md5($_POST['password'])."'";


$result = mysql_query($query);


$numrows = mysql_num_rows($result);


if ($numrows!=1){
$errors[] = 'Username or Password Incorrect';
} else{



$row = mysql_fetch_array($result);
$type = $row['type'];

if ($type=="0") {
$_SESSION['chef'] = $username;
header("Location: chefpanel.php");
}else{
$_SESSION['rest'] = $username;
header("Location: restpanel.php");
}}
?>

Link to comment
Share on other sites

md5() simply takes a string and runs the md5 hash algorithm on it, turning it into a hash value.  It's also what is called a 1-way hash, in that it is not like encrypt/decrypt where the value can be unencrypted. 

 

If you stored md5() version of the passwords when the accounts were created, then you can expect that this query might work.  If not, then these will never match.  The password column would need to be a 32 character string for this to work.

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.