Jump to content

Secure login/class?


stuffradio

Recommended Posts

I also want to be protected against session hijacking and cookie hijacking(if I use cookies).

 

This is a tough issue and i have read up on it. Basically, unless you login system and back-end is behind an SSL connection you're not going to have total security, you'll have security-through-obscurity.

 

I just finished writing an authentication class for my back-end and I settled on this solution.

 

Basically, unless you login system and back-end is behind an SSL connection you're not going to have total security, you'll have security-through-obscurity.

 

You __can't__ rely on the ip_address or the http_user_agent to stay the same across the session because some ISP's will cause false or different values for both, even during the same session.

 

What i did was use a technique called a request and expiration. Basically, every time the user makes a request to continue the session they submit with their session_id, a request code that was generated on their last access. That code must match what's stored in the session. The code changes each time the user access the session. This allows for a bit more security, but it by no means prevents session hijacking -- it just makes it harder.

 

I just allowed the user to choose if they would like to enabled ip_address and http_user_agent checking. I also added a lockdown feature if an account had too many failed attempts to login, its a double edge sword because anyone can just bombard the account and cause the real user to get locked out as well. (again an option). Finally (i got this idea from a bank) i added a time lock feature that only allows users to login during certain parts of the day.

 

Hope this helps

Link to comment
Share on other sites

redbrad, what you typed is pseudo-code, just for future reference. It's just where you use a vaguely code-like style to put accross what you mean in real english.

 

I use a variety of techniques. The main one is to use session ID's, and only allow them to be used for a short time. regenerating sessions is one of my favourites. Store the session id in the database, and regenerate it every 10 pageviews or so - it helps to avoid session spoofing at least.

 

Store as little as possible in the session, don't store any actual data in it, just references to things you have in your DB.

 

Avoid cookies where possible. It doesn't take much effort on the part of the user to log in each time they visit, but if you provide them with an auto-login feature you've done half the breaking in yourself.

 

Store a combination of IP/user agent/session id in the database - okay, they're not perfect, but it works the vast majority of the time.

 

As with any security, it's getting the balance of protecting your data and making your app as easy as possible to use. In general.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.