Hey Guys,
Nice thread...I have been wondering for a while now if the way I handle my security is ok.
This is what i use:
Code:
class Security {
function login($user, $pass) {
$db = new DBClass;
$sql = sprintf("SELECT pkiUserID, bPermissionsLevel FROM t_gallery_users WHERE sUsername=%s AND sPassword=%s",
quote_smart($user),
quote_smart(md5($pass)));
$db->query($sql);
if($db->next_record()) {
SetSession("userID",$db->f(0));
SetSession("secLevel",$db->f(1));
SetSession("secureCheck",md5($pass));
$db->close();
return true;
} else
return false;
}
function securityCheck() {
if((isset($_SESSION['secureCheck']))&&(isset($_SESSION['userID']))) {
$db = new DBClass;
$sql = sprintf("SELECT pkiUserID FROM t_gallery_users WHERE pkiUserID=%o AND sPassword=%s",
quote_smart($_SESSION['userID']),
quote_smart($_SESSION['secureCheck']));
$db->query($sql);
if($db->next_record()) {
return true;
}
}
return false;
}
function logout() {
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
}
}
I just use the class to group functions, no other reason...
securityCheck() is called by every page (so that query is run every time).
Any advice/comments would be greatly appreciated.
Bookmarks