Jump to content

trying to secure my login data being sent to mysql safetly


jasonc

Recommended Posts

the first two codes are what i have got from another project i worked on but i can not login in now using them.

 

i get my error message that the login failed.

i have also tried to echo the query and get this following.

 

SELECT * FROM `users` WHERE `username` = 'myuser' AND binary `passwordfield` = 'mypassword' LIMIT 1

 

can anyone see why this is not working?

 

  function db_query($query, $link = 'db_link') {
    global $$link;

    $result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error());
    return $result;
  }


//Add slashes to incoming data
  function db_input($string, $link = 'db_link') {
    global $$link;

    if (function_exists('mysql_real_escape_string')) {
      return mysql_real_escape_string($string, $$link);
    } elseif (function_exists('mysql_escape_string')) {
      return mysql_escape_string($string);
    }

    return addslashes($string);
  }

 

$username = strtolower(trim($_POST['name']));
$password = trim($_POST['password']);
$sql = "SELECT * FROM `users` WHERE `username` = '".db_output($username)."' AND binary `passwordfield` = '".db_output($password)."' LIMIT 1";
db_query($sql);

 

 

 

my original code was just this...

// $res = @mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND binary `passwordfield` = '".$password."' LIMIT 1") or die(mysql_error());

which works but i have found is not very secure

 

so the two codes at the top are what i have used from another project i had once.

 

but for some reason the login does not work.

 

i get my login failed error mesages.

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.