mat3000000 Posted January 28, 2011 Share Posted January 28, 2011 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"); }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/226001-help-with-md5/ Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 Is the password stored in the database as an md5() hash, or is it stored in plain text? Quote Link to comment https://forums.phpfreaks.com/topic/226001-help-with-md5/#findComment-1166736 Share on other sites More sharing options...
gizmola Posted January 28, 2011 Share Posted January 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226001-help-with-md5/#findComment-1166739 Share on other sites More sharing options...
jcbones Posted January 28, 2011 Share Posted January 28, 2011 Check your table structure to make sure the column will hold a md5 hash. The password column would need to be a 32 character string Quote Link to comment https://forums.phpfreaks.com/topic/226001-help-with-md5/#findComment-1166745 Share on other sites More sharing options...
mat3000000 Posted January 29, 2011 Author Share Posted January 29, 2011 Had set the limit of pass field to 30 chars! oops! Thanks For all the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/226001-help-with-md5/#findComment-1167070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.