Jump to content


Photo

Writing Security Checks for Homegrown CMS. Running Into Problems.


  • Please log in to reply
1 reply to this topic

#1 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 September 2006 - 07:01 AM

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.

    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.
     }

You are the weakest Uniform Resource Locator... Goodbye.

#2 contrabandheart

contrabandheart
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 September 2006 - 10:18 PM

Ahem.

Bump.

I'll be happy to provide any clarification if it's needed.
You are the weakest Uniform Resource Locator... Goodbye.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users