Jump to content


This topic is now archived and is closed to further replies.


Writing Security Checks for Homegrown CMS. Running Into Problems.

Recommended Posts

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.

    $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);
    if(!isset($_COOKIE['ccms_failed_login_attempts']) or $_COOKIE['cms_failed_login_attempts'] == 0){
    elseif(isset($_COOKIE['ccms_failed_login_attempts']) and $_COOKIE['ccms_failed_login_attempts'] >= 1){
      $attempts = $_COOKIE['ccms_failed_login_attempts'];
      setcookie("ccms_failed_login_attempts",$attempts + 1,time()+3600);
      //... And insert a value into a table in MySQL marking someone as banned.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.