Jump to content

Send password as md5


cloudsurferuk

Recommended Posts

Hi, How can I change this so it injects the password as md5?

 

$sql="INSERT INTO pilots (name, email, password, Age, city, country, vatsim_id, previous_va, previous_hours)
VALUES
('$_POST[name]','$_POST[email]', '$_POST[password]','$_POST[Age]','$_POST[city]','$_POST[country]','$_POST[vatsim_id]','$_POST[previous_va]','$_POST[previous_hours]')";

Link to comment
https://forums.phpfreaks.com/topic/191247-send-password-as-md5/
Share on other sites

$sql="INSERT INTO pilots (name, email, password, Age, city, country, vatsim_id, previous_va, previous_hours)
VALUES
('$_POST[name]','$_POST[email]', 'md5($_POST[password])','$_POST[Age]','$_POST[city]','$_POST[country]','$_POST[vatsim_id]','$_POST[previous_va]','$_POST[previous_hours]')";

Hi,

 

You never want to insert post variables directly into your SQL. It leaves it wide open for SQL injection.

 

What happens when someone uses an apostrophe in one of those fields?

 

$name = addslashes($_POST['name']); //always use addslashes to escape any apostrophe characters
$email = addslashes($_POST['email']);
$password = md5($_POST['password']); //use md5 for password
$Age = intval($_POST['Age']); //use intval if it is supposed to be an integer
$city = addslashes($_POST['city']);
$country = addslashes($_POST['country']);
$vatsim_id = intval($_POST['vatsim_id']); //use intval if it is supposed to be an integer
$previous_va = addslashes($_POST['previous_va']);
$previous_hours = intval($_POST['previous_hours']); //use intval if it is supposed to be an integer

$sql="INSERT INTO pilots (name, email, password, Age, city, country, vatsim_id, previous_va, previous_hours)
VALUES
('$name', '$email', '$password', $Age, '$city', '$country', $vatsim_id, '$previous_va', $previous_hours)";
//notice you don't need singlequotes around integers in the VALUES() clause.

Ok so the sign up side is sorted but this code is used to process the login, and I cant get it working.. anything obvious?

 

$username = $_POST['username'];    
$password = md5 $_POST['password'];    
$time = time();            
$check = $_POST['setcookie'];        

$db = mysql_connect($dbHost,$dbUser,$dbPass); 
mysql_select_db($dbname,$db);                     

$query = "SELECT username, password FROM pilots WHERE username = '$username' AND password = 'md5 ($password)'";
$result = mysql_query($query, $db);
if(mysql_num_rows($result)) {    
   $_SESSION['loggedin'] = 1;       

    if($check) {
    
    setcookie("fsuk[username]", $username, $time + 3600);        
    setcookie("fsuk[password]", $password, $time + 3600);    
    }

   header('Location: index.php'); 
   exit();
}
else    
{
   header('Location: crewlogin.php?error=1');
   exit();
}
?>

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.