login - Whats the best way to do user authentication in php? -
I'm just writing 2 cookies, 1 in which the user ID is, and 1/2 of the SH1 hash is password ( Salty) The way it works, it is self-evident.
I realized that I was not doing it the safest way. What is a better way to do this? Preferably using a single authentication cookie.
Also, is there any point in using "hard to calculate hash"? That means, using bcrypt, or husing 10,000 items with whirlpool each time, it has to do (relatively) slow hash function (less than 1 mS vs. 1 ms only) SHA1? I mean that someone violates your DB and takes the senses ... what's left there to protect it, because all your data is in one DB (unless you have some type of D- Centralized setup is not what I'm not). / P>
Store session IDs in the cookie, and log on to the user's status server side (logs) In, user id, ip).
To illustrate what you need to store in the session array:
- Login: A Boolean variable about which user login Yes or No . You can reuse the same cookie for multiple sessions so that you remember the user's username the next time they come to your site.
- userId: User's uniqe id in the database. Use this to get more information about users like usernames, emails etc. Even after the user is logged out, it can be placed in the session array.
- IP: To prevent someone from stealing and using the session ID, you can also store the user's IP. This is optional, because sometimes you want to allow the user to roam (for example, the Stavekfl flow allows me to change the IP when allowing me to go with my laptop without logging out).
- lastPing: The user has finally seen the timestamp. It can be used instead of the cookie expiration date. If you also store the session's Lifetime , you can log out the user due to inactivity. This means that the session ID cookie can be stored on users' computers for a very long time.
When the user logs out or logs out due to inactivity, then you only set logged
to false. When the user logs in with the correct username and password, then you really set loggedIn
and update other fields (UserID, IP, Lifetime). When the user loads a page, you can check the current time and the last ping
with
The session data can either be stored in the filesystem or database if a database is stored in the userId user record is a foreign key, or all the data can be kept in the user's records. .
hashing
A value is not a good idea again several times because you use salt instead, a permanent salt (the name of the page for example) and the user's user With the name, with password. A hash that takes longer, is not better than fast hashes, a hash that is better than a hash as a result of large digestion, resulting in less digestion (due to brute force) using SHA1 is a normal site ( IE, a bank or a secret military organization) should be enough.
Comments
Post a Comment