Jump to content

Writing Security Checks for Homegrown CMS. Running Into Problems.


contrabandheart

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.

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.