+ Reply to Thread
Results 1 to 3 of 3

Thread: mysql login

  1. #1
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member droctoganapus86 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    49

    Question mysql login

    Code:
    		$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
    this line of code is giving me this error :
    Code:
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/tomx/public_html/demo/demo.php on line 58
    anyone knows what to change?

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: mysql login

    Replace the line with:

    Code:
    $sql = "SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'" ;
    
    echo $sql . "<br />\n" ;
    
    $res = mysql_query( $sql ) ;
    
    if( $res ){
       // process the result
    } else {
    
     echo: 'ERROR: ' . mysql_error();
    
    }
    and see what you get.

    I'll let mission comment on using mysql_ instead of PDO or at least mysqli_ and also your vulnerability to SQL injection.
    Nothing is always absolutely so.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: mysql login

    You rang?

    Time for the boilerplate:

    The sample code is vulnerable to SQL injection via $_POST['username'], which is a very serious security risk. To fix this hole, switch from the outdated mysql extension to PDO and use prepared statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.

    MD5 is considered broken by security professionals. Use a newer hashing function, such as whirlpool or something from the SHA2 family (SHA256, SHA512). No less than Bruce Schneier has written:
    But -- come on, people -- no one should be using MD5 anymore.
    Your password scheme is also vulnerable to rainbow tables. Add salt to fix this. You could use the username + a system salt, or give each user a unique salt (a "nonce") and store that in a column in table `users`.

    To update your code without impacting existing users:
    1. Add a new column to your users table indicating which hash function was used. It could be a BOOLEAN value indicating that the p/w needs updating, or a string naming the hash function:
      1. `md5` BOOLEAN NOT NULL DEFAULT TRUE,
      2. `hash` VARCHAR(16) NOT NULL DEFAULT 'md5',
      The latter option allows you to easily support whatever hashing functions are available on the host.
    2. Register new users using the newer hashing function.
    3. When a user logs in, check whether their password is hashed using MD5 or not. If it is, expire their password. This is a good chance to have users enter new passwords.
    4. If using the 1st column option, drop the column when there are no more MD5 hashed passwords (SELECT COUNT(*) FROM users WHERE `md5`=TRUE is 0)
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Can't login to cPanel & MySql
    By parasait in forum Free Hosting
    Replies: 1
    Last Post: 07-26-2010, 10:31 PM
  2. MYSQL login name denied
    By Dhryn in forum Free Hosting
    Replies: 3
    Last Post: 06-28-2010, 05:43 AM
  3. MySql Login
    By bensrevenge in forum Free Hosting
    Replies: 5
    Last Post: 03-24-2010, 02:25 PM
  4. cant login to mysql
    By bioshock in forum Free Hosting
    Replies: 2
    Last Post: 01-24-2010, 01:40 PM
  5. MYSQL server for PHP login
    By wtvelocity in forum Free Hosting
    Replies: 3
    Last Post: 06-05-2008, 11:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers