php - What is the most secure method of logging someone into a website? -


i trying ascertain best way keep logged website after have verified log in correct.

i tried have @ "keep me logged in" - best approach upvoted answer said should generate token , store token in database! surely wholly unsecure because takes database hack , cookie editing elses account?

could please provide me date secure way of doing this? thanks.

we posted blog secure authentication long-term persistence (a.k.a "remember me"), largest difference between blog post , ircmaxell's answer "keep me logged in" - best approach separation of lookup (which not constant-time) , validation (which constant-time).

in strategy outlined in our blog post, aren't storing tokens in database, you're storing sha-256 hash of token. if attacker leaks these values, has crack sha-256 hashes of strong random tokens. they're better off launching reverse shell lets them authenticate user (or proceed take on entire machine local kernel exploit).

logging in (simple , basic)

  • use bcrypt. password_verify(). don't generate own salts.

    if want go mile, consider bcrypt + aes library encrypt password hashes (which helpful if have database , webserver on separate hardware, since compromising database won't give them encryption key).

  • rate-limit failed attempts. example: after 5 failures per ip or username, require captcha.

long-term persistence ("remember me")

when logging in:

  1. generate secure random token.
  2. generate secure random identifier.
  3. store identifier , token in rememberme cookie.
  4. store sha256 hash of token in database.
  5. when user lands on page, if have rememberme cookie, grab identifier , database search.
  6. if there authentication token identifier, grab sha256 hash.
  7. compare hash of token provided cookie sha256 hash in database using hash_equals().
  8. if succeeds, set session variable user's id. generate new token. if fails, delete entry database.

advantages of strategy

  • if successful sql injection attack leads tokens being leaked, attacker has sha256 hash of various tokens. not helpful compromising accounts.
  • database searches not constant-time. why identifier separated token.
  • sequential identifiers leak activity level of application, many businesses wish keep confidential. random identifier obfuscates detail.

disadvantages

  • (future stackoverflow authors should feel free populate list if discovered.)

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -