PHP/MySQL/SESSION login technique

Discussion in 'PHP' started by mma freeroll, Feb 19, 2009.

  1. #1
    On one of my websites, I want to add a "login" feature.

    This is how I was thinking about doing it -

    1. The user enters their username and password in the form
    2. The resulting PHP page tries to match that username and password to one in a MySQL database
    3. If that combination is not found, they are redirected back to the login page with a ?login=failed query string attached
    4. If that combination is good, a session is created with a random 20 character string as a value and the username as a value
    5. Two cookies are also created, one with the random string and one with the username
    6. Every page of the "my account" section will check both the 20 character string and the username cookies to make sure they match the session
    7. If either one doesn't match, or the session no longer exists, they are considered "logged out"

    What do you guys think?
     
    mma freeroll, Feb 19, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    I think its enough "complex" - goodluck with using it
     
    crivion, Feb 19, 2009 IP
  3. mma freeroll

    mma freeroll Guest

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the response, crivion. Would you recommend something else?

    I'm looking for the most secure, or at least the "industry standard" for login systems.

    Thanks!
     
    mma freeroll, Feb 19, 2009 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What is the point of the username cookie? You can just store that in the session. It doesn't provide any additional security.

    It's possible that a browser can be coerced into sending cookies on a forged request. If your site has interactive forms, you may also want to send a token with each form and confirm that you get the same one back in the posted variables - one more layer of confirmation that you're dealing with who you think you are.

    Some sites will also drop the login if the IP address changes, but that can be quite annoying for users on certain proxy servers, mobile devices, etc., who may have their external IPs constantly changing.
     
    SmallPotatoes, Feb 19, 2009 IP