PDA

View Full Version : [PHP] IP.Board auth



Josh
07-22-2013, 08:55 AM
Simple IP.Board auth. I got bored last night and decided to see if I still remembered some php...


<?php
include 'conf_global.php';

if ($_GET["r"] AND $_GET["u"] AND $_GET["p"]){


$dbusername = $INFO['sql_user'];
$dbpassword = $INFO['sql_pass'];
$hostname = $INFO['sql_host'];
$database = $INFO['sql_database'];
$r = $_GET["r"];
$username = mysql_real_escape_string($_GET["u"]);
$password = $_GET["p"];

$show_groups = false;
//Will list groups and their ID number. Keep on false usually. Just helpful for writing the rank checking part of the code.




$dbhandle = mysql_connect($hostname, $dbusername, $dbpassword)
or die("Unable to connect to MySQL");

$selected = mysql_select_db($database,$dbhandle)
or die("Could not select database");
$result = mysql_query("SELECT * FROM `forum_members` WHERE name = '$username'");
$row = mysql_fetch_array($result);


if (empty($row)) {

echo "<error>Invalid username</error>";

}
else{
$getsalt = $row{'members_pass_salt'};

$hash = md5(md5($row{'members_pass_salt'}). md5($password));
if($hash != $row['members_pass_hash']){

echo "<error>Invalid Password</error>";
}
else{
$get_rank_id = $row{'member_group_id'};
$ranks = array(-1 => '1', 0 => '5', 1 => '3', 2 => '6', 3 => '4');
//List of all rank ids. Current ones are the default groups for IP.Board
//Numbers in quotes are the IDs of the group.
//1 = Validating
//5 = Banned
//3 = Members
//4 = Admins
//6 = Mods
//First number ranks those groups from least to greatest. 0 and below = Access to nothing.
// There are others ways of doing this, but this was easy.

$rank = array_search($get_rank_id, $ranks);

if($rank >= $r){
echo "Posts: <posts>".$row{'posts'}."</posts>"." <rank>".$row{'member_group_id'}."</rank>";
echo "<error>Success</error>";
}else{
echo "<error>Rank not high enough</error>";
}




}

}



if ($show_groups) {
echo "<br><br><table border='1'>
<tr>
<th>ID</th>
<th>Group Name</th>
</tr>";


$result = mysql_query("SELECT * FROM `forum_groups`");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['g_id'] . "</td>";
echo "<td>" . $row['g_title'] . "</td>";
echo "</tr>";
}
echo "</table>";


}

mysql_close($dbhandle);
} else{
echo "...You forgot something";
}
?>