I have already created and refined both registration and login systems, However I am lead to believe the tricky part comes when you are creating a session. As far as I know this is due to both Hijacking and fixation. Which in all honesty I don't fully understand the concept of.
I have browsed the internet all day and done a large amount of research. he following articles have been useful to me so far:
How to Create Bulletproof Sessions
So far I have very little, I could really use some help and guidance. This is some of what I have got so far:
When a users password is matched and they have confirmed their identity using the login script the following function is called. The session is started at the top of the login script.
function begin_session()
{
session_regenerate_id();
$_SESSION['valid'] = 1;
$_SESSION['fingerprint'] = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR']);
}
I am using the $_SESSION['valid'] variable as a simple the user is logged in confirmation. I am assigning the session to a single User Agent and IP Address. I see how the User Agent is fairly useless as it can be easily forged but I feel it's better to have it rather than not have it.
It's apparent to me users with changing/dynamic ip's would be logged out... but everyone who has told me this has failed to present me with a better option, or explain it to me better.
I am then using the following function to match the current user agent to the original user agent logged at the creation of the session.
function authenticate()
{
session_start();
if ($_SESSION['fingerprint'] != md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'])) {
session_destroy();
echo 'die';
header('Location: http://website login page/');
exit();
}
}
At the moment due to my lack of understanding, I don't know where I am vulnerable from and or where I can go and make improvements. This is all very new to me and at the moment at least I am trying to learn this in my spare time. It's all new to me, and I want to ensure the best work.
session.hash_function
andsession.hash_bits_per_character
ini settings. Creating your own session IDs from a purely random source would still be preferred though. – Leigh Nov 14 '12 at 11:55