Jump to content
Larry Ullman's Book Forums

I Need Help On Limiting The Login Attempts


Recommended Posts

Add a wrong_logins column to whatever users table. For each wrong login, increase this by 1. Add a wait_logins column of type TIMESTAMP. When wrong_logins gets to 5, update this column to NOW() plus 15 minutes. When the user properly logs in, set wrong_logins to 0 and wait_logins to NULL. Add a check to the login process that wait_logins must be NULL.

 

That's the basic idea.

Link to comment
Share on other sites

Add a wrong_logins column to whatever users table. For each wrong login, increase this by 1. Add a wait_logins column of type TIMESTAMP. When wrong_logins gets to 5, update this column to NOW() plus 15 minutes. When the user properly logs in, set wrong_logins to 0 and wait_logins to NULL. Add a check to the login process that wait_logins must be NULL.

 

That's the basic idea.

Thanks Larry.

I will try it and let you know>

Link to comment
Share on other sites

I tries this and it worked.

is it good enough ?

 

$q = " select username, password, login_count, wait_login from users where username = '$username' and password = '$password' limit 1 ";

$r = mysql_query($q, $con);

confirm_query($r);

if(mysql_num_rows($r) == 1){

$row = mysql_fetch_array($r);

$wait_login = $row['wait_login'];

if($wait_login > time()){

echo " you are locked out for 15 minutes";

}else {

echo "You are logged in!";

$q = " UPDATE users set login_count = 0 where username = '$username' ";

$r = mysql_query($q, $con);

confirm_query($r);

}

} else {

echo "Incorrect password!";

$q = " UPDATE users set login_count = login_count +1 where username = '$username' ";

$r = mysql_query($q, $con);

confirm_query($r);

$q = " SELECT login_count, wait_login from users where username = '$username' ";

$r = mysql_query($q, $con);

confirm_query($r);

$row = mysql_fetch_array($r);

$login_count = $row['login_count'];

$login_wait =$row['wait_login'];

if($login_count>5){

echo " You are locked out for 15 Minute!";}

elseif($login_wait<=time()){

$q = " UPDATE users set wait_login ='$lockout' where username = '$username' ";

$r = mysql_query($q, $con);

confirm_query($r);

}

}

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...