mysql_real_escape_string and strip_tags for password $_POST

Discussion in 'PHP' started by ycpc55, May 27, 2012.

  1. #1
    hi
    i was wondering if you should use the mysql_real_escape_string and strip_tags for the password $_POST here is what im talking about below reason im asking this is i been reading a lot of post and people where saying no to use it for the password $_POST thanks.

    
    keep it like this:
    $password = $_POST["password"];
    
    this:
    $password = stripslashes($post['password']);
    
    or this:
    $password    = mysql_real_escape_string(strip_tags($_POST['password']));
    
    PHP:

     
    ycpc55, May 27, 2012 IP
  2. Deltazon

    Deltazon Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Why don't you want to use the mysql_real_escape_string only?
     
    Deltazon, May 27, 2012 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    Your code suggests that you will store the password as plain text which is a very bad practice

    The use of stripslashes relies on a depracated (PHP 5.3.0) and then abondonned (PHP 5.4.0) feature : Magic Quotes
    Drop the need for stripslashes by setting magic_quotes_gpc to off in your php.ini configuration file.

    The lowest acceptable approach is to encode passwords using md5() before storing them,you won't need mysql_real_escape_string, strip_tags because md5() function returns 32 hexadecimal characters.

    
    $username = $_POST['username'];
    $username = sanitize($username);  /* This should remove any tricky or unacceptable characters */
    
    $password = $_POST['password'];
    $password_encrypted = md5($password);
    
    mysql_query("INSERT INTO users (username, password) VALUES ($username, $password_encrypted) ");
    
    
    PHP:
     
    nabil_kadimi, May 27, 2012 IP
  4. ycpc55

    ycpc55 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi im using this for my password
    $password = hash('sha512', $_POST['password']);
    PHP:
    thanks for replying guys
     
    ycpc55, May 27, 2012 IP
  5. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #5
    If you're hashing the password before you send it to the DB, you don't need to use mysql_real_escape_string or stripslashes.
     
    kbduvall, May 28, 2012 IP