|
PHPRunner Example
<?
function BeforeLogin($username, $password)
{
//********** Custom code ************
// check if this IP address is currently blocked
global $conn;
$sql = "select Attempts, LastLogin from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'";
$rs = db_query($sql,$conn);
$data = db_fetch_array($rs);
if (!$data || !strlen($data["LastLogin"]))
return true;
$atime = db2time($data["LastLogin"]);
$time = mktime($atime[3],$atime[4],$atime[5],$atime[1],$atime[2],$atime[0]);
$diff = (time()-$time)/60;
if ($data["Attempts"]>=3)
{ if($diff<30)
{
echo "<p align=center><br><font
color=red><b>Access denied for 30 minutes</b> <font></p>";
return false;
}
else
{
db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn);
return true;
}
}
return true;
}
function AfterSuccessfulLogin()
{
//********** Custom code ************
// clear previous attempts
global $conn;
db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn);
}
function AfterUnsuccessfulLogin()
//********** Custom code ************
// increase number of attempts
// set last login attempt timeif required
{
global $conn;
$sql = "select * from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'";
$rs = db_query($sql,$conn);
$data = db_fetch_array($rs);
if($data)
{
$attempts = $data["Attempts"]+1;
if($attempts==3)
db_exec("update LoginAttempts set Attempts=" . $attempts . ",
LastLogin=now() where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn);
else
db_exec("update LoginAttempts set Attempts=" . $attempts . "
where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn);
}
else
db_exec("insert into LoginAttempts (Attempts,IP,LastLogin) values (1, '".$_SERVER["REMOTE_ADDR"] . "',NOW())",$conn);
}
?>
|