contrabandheart Posted September 2, 2006 Share Posted September 2, 2006 Okay. So first, I'll give you a quick rundown of what it is I'm trying to do. I have a username and password field on a login page for a CMS script I'm currently writing. I already have all of the code for checking for empty fields, and now I'm on to securing it from people trying to brute force their way in (Not that anyone would care enough to do so, but I just want to be impressed with myself.) The snippet of code that I'm trying to get to work should function thusly:If you enter a username that doesn't exist, a cookie called "ccms_failed_login_attempts" is set with a default value of "1 (for one failed login)". After that, a piece of code checks to see if "ccms_failed_login_attempts" is set with a value of "1" (or set at all, for that matter). If it exists, it should load the cookie's value. After that, if the attacker tries to use another bogus username, the code should load and then reset "ccms_failed_login_attempts" to the current value plus 1 (i.e., if you have tried twice, it should load the cookie and reset it as three). *hopes any of this is making sense*.I'll insert the code below, hoping someone will help me. Thanks in advance.[code] connect2db("********"); $sql = "SELECT user_id FROM `users` WHERE `user_name` = '$user_name' LIMIT 1;"; $result = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($result) == "0"){ header("Location: " . $PHP_SELF); setcookie("ccms_status","loginBadUsername",time()+1); if(!isset($_COOKIE['ccms_failed_login_attempts']) or $_COOKIE['cms_failed_login_attempts'] == 0){ setcookie("ccms_failed_login_attempts","1",time()+3600); } elseif(isset($_COOKIE['ccms_failed_login_attempts']) and $_COOKIE['ccms_failed_login_attempts'] >= 1){ $attempts = $_COOKIE['ccms_failed_login_attempts']; setcookie("ccms_status","loginBanned",time()+1); setcookie("ccms_failed_login_attempts",$attempts + 1,time()+3600); //... And insert a value into a table in MySQL marking someone as banned. }[/code] Quote Link to comment Share on other sites More sharing options...
contrabandheart Posted September 2, 2006 Author Share Posted September 2, 2006 Ahem.Bump.I'll be happy to provide any clarification if it's needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.