Here's my current system.
Please let me say before you look at this, I know it's completely lacking in regards to security. This was kind of a placeholder so I could get all the pages and functions working. I'm wondering if this system can be transformed into a relatively secure persistent login system.
Checking their Login:
/* get the incoming ID and password hash */
$username = mysql_real_escape_string(substr(strtolower($_POST["username"]), 0, 15));
$password = mysql_real_escape_string(substr(sha1($_POST["password"]), 0, 40));
/* Are we working with a legitimate login? If so, give them the proper permissions. */
$query="SELECT * FROM users WHERE username='$username' AND password='$password'";
$result=mysql_query($query) or die (mysql_error());
$numr=mysql_num_rows($result);
if($numr==1){
while($row=mysql_fetch_array($result)){
$userid=$row['userid'];
$username=$row['username'];
$userperms=$row['perms'];
}
session_start();
header("Cache-control: private");
$_SESSION['access'] = $userperms;
$_SESSION['userid']=$userid;
$_SESSION['username']=$username;
$_SESSION['name_first']=$name_first;
$_SESSION['name_last']=$name_last;
if(ISSET($_SESSION['return_url'])){
header("Location: ".$_SESSION['return_url']);
}else{
if($userperms>='2'){
header("Location: ./overlord.php");
}else{
header("Location: ./index.php");
}
}
}else{
/*Flag them as a failed login and send them back to try again.*/
session_start();
$_SESSION['access'] = "denied";
header("Location: ./index.php?content=login");
}
Authentication on page load:
/*Do the authentication boogaloo.*/
header("Cache-control: private");
if(ISSET($_SESSION['access'])){
if ($_SESSION['access'] == "3"){
$userperms='3';
}else{
if ($_SESSION['access'] == "2"){
$userperms='2';
}else{
if ($_SESSION['access'] == "1"){
$userperms='1';
}
}
}
}else{
$userperms='0';
}
Any hope of converting this into something I can use?
thanks,
json