PHP Login Help

Discussion in 'PHP' started by Obulus, Apr 15, 2010.

  1. #1
    I need help!

    I'm in the process of building a small login system.. the only things that need to be entered at a username and password but I always fail when it comes to securing it up.

    What things should I do to aid with the securing of it? What things should I secure against?

    If anyone could post examples of good secure logins for me to educate myself from, I'd be extremely appreciative.

    Thanks!
     
    Obulus, Apr 15, 2010 IP
  2. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One thing you can do is change over to using the mysqli function in php and using prepared statements to clean input but heres some basic cleaning for sql injections

    <?php
    $query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
                mysql_real_escape_string($user),
                mysql_real_escape_string($password));
    mysql_query($query);
    
    ?>
    Code (markup):
     
    atlantaazfinest, Apr 15, 2010 IP
  3. Obulus

    Obulus Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your help! I'll take it into consideration!
     
    Obulus, Apr 15, 2010 IP
  4. aTo

    aTo Active Member

    Messages:
    473
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #4
    here is a good post... found on the net... :) its useful

    Click here...
     
    aTo, Apr 15, 2010 IP
  5. rajamanickam.a

    rajamanickam.a Well-Known Member

    Messages:
    636
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    158
    Digital Goods:
    2
    #5
    Can anyone explain with simple example how the hackers can misuse the login system if we are not following these steps?

    atlantaazfinest,
    You mean "REPort Post" button? :)
     
    rajamanickam.a, Apr 16, 2010 IP
  6. aTo

    aTo Active Member

    Messages:
    473
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #6
    Check this post here

    i guess it is in the QUESTION NUMBER 3.. maybe it will come useful, just to bear in mind... :)
     
    aTo, Apr 16, 2010 IP
  7. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    store the users password using forward php encryption, sha1() and then md5(), upon checking if passwords match just forward ecrypt the posted string in the same way and run the query.
     
    jeanmichel, Apr 17, 2010 IP
  8. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    LOL...

    And example if you don't sanitize the input a hacker can do
     ' OR 1=1 ;-- 
    Code (markup):
    what that will do is make the query look something like this

    password='' OR 1=1;-- (Makes the rest of the query a comment)

    and therefore 1 is equal to 1 so it will return an entry based on the other parameters they put in ex username giving them authentication.
     
    atlantaazfinest, Apr 19, 2010 IP
  9. Li0rE

    Li0rE Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Create a sessions table in your database and use a cookie to reference which session it is instead of keeping all info in a cookie.
     
    Li0rE, Apr 19, 2010 IP