Cotton Rohrscheib

The Cotton Club Blog & Podcast

  • Home
  • Bio
    • Resume
  • Blog
    • Faith & Family
    • Marketing & Tech
    • Farm & Business
    • Entertainment
    • Health & Wellness
    • Urban Farming
    • Weekend Projects
  • Media
    • Newsletter
    • Photo Galleries
    • Instagram Feed
    • Video Archives
    • Podcasts
    • Music Playlists
  • Books
  • Connect
    • Rohrscheib Capital
    • Disclaimer
    • Privacy Policy
You are here: Home / Marketing & Tech / Locking Down Authentication Inside PHPRunner

Locking Down Authentication Inside PHPRunner

July 26, 2009 by Cotton Rohrscheib Leave a Comment

One of the biggest challenges you face when building hosted applications is how to prevent brute force or guessed password authentications.  Especially given the number of warez type applications that are out there that allow unsavory users to do just that.  Well, I found a resource on Xlinesoft’s website that demonstrates how to do block a user after three unsuccessful attempts to login to your application.

This schema uses visitors IP address to store log attempts in the database and block access to to the login feature for 30 minutes after the third unsuccessful attempt. This schema involves Events function which is available in ASPRunnerpro 6.0/PHPRunner 5.0, I have reposted the processes involved for PHPRunner below, but you can find the ASPRunner notes here…

Step One:
In MySQL Server run the following script to create table in your database that logs login attempts. The box below demonstrates the MySQL command.

   1: CREATE TABLE `LoginAttempts`
   2: (
   3: `IP` VARCHAR(20) NOT NULL,
   4: `Attempts` INT NOT NULL,
   5: `LastLogin` DATETIME NOT NULL
   6: )

Step Two:

Open your PHPRunner project and go to the security tab and switch on the “Create Login Page” checklist.

Check the Username and password from database option and choose appropriate fields. If you have no table in which all of the login details are stored you have to create it.

Step Three:

Add three global events on the Events tab: BeforeLogin, AfterSuccessfulLogin, AfterUnsuccessfulLogin.  Below you will find the PHPRunner example for this:

   1: <?
   2: function BeforeLogin($username, $password)
   3: {
   4: //********** Custom code ************
   5: // check if this IP address is currently blocked
   6: global $conn;
   7: $sql = "select Attempts, LastLogin from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'";
   8: $rs = db_query($sql,$conn);
   9: $data = db_fetch_array($rs);
  10:  
  11: if (!$data || !strlen($data["LastLogin"]))
  12:   return true;
  13:  
  14: $atime = db2time($data["LastLogin"]);
  15: $time = mktime($atime[3],$atime[4],$atime[5],$atime[1],$atime[2],$atime[0]);
  16: $diff = (time()-$time)/60;
  17:  
  18: if ($data["Attempts"]>=3)
  19: {
  20:   if($diff<30)
  21:   {
  22:     echo "<p align=center><br><font color=red><b>Access denied for 30 minutes</b> <font></p>";
  23:     return false;
  24:   }
  25:   else
  26:   {
  27:     db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn);
  28:     return true;
  29:   }
  30: }
  31: return true;
  32: }
  33:  
  34: function AfterSuccessfulLogin()
  35: {
  36: //********** Custom code ************
  37: // clear previous attempts
  38:  
  39: global $conn;
  40: db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn);
  41:  
  42: }
  43:  
  44: function AfterUnsuccessfulLogin()
  45: //********** Custom code ************
  46: // increase number of attempts
  47: // set last login attempt timeif required
  48: {
  49: global $conn;
  50: $sql = "select * from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'";
  51: $rs = db_query($sql,$conn);
  52: $data = db_fetch_array($rs);
  53:  
  54: if($data)
  55: {
  56:   $attempts = $data["Attempts"]+1;
  57:  
  58:   if($attempts==3)
  59:     db_exec("update LoginAttempts set Attempts=" . $attempts . ", LastLogin=now() where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn);
  60:   else
  61:     db_exec("update LoginAttempts set Attempts=" . $attempts . " where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn);
  62: }
  63: else
  64:   db_exec("insert into LoginAttempts (Attempts,IP,LastLogin) values (1, '".$_SERVER["REMOTE_ADDR"] . "',NOW())",$conn);
  65: }
  66: ?> 

Step Four:

You should finish the code generation / compiling process and upload your application.  It’s important to remember that by doing this, your visitors have to enter their username and password to gain access to the site. After the third unsuccessful login attempt, their IP addresses access will be denied for 30 minutes. When the visitor tries to login when the account is blocked they will see message saying access is denied.

Find out how to do this for ASPRunner also…

——————————————————————

There are a lot of other useful resources outlined for PHPRunner users in the Articles section on Xlinesoft’s website, you can find them here…

Share this post on:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest

Related

About Cotton Rohrscheib

The Cotton Club is a monthly podcast hosted by me, Cotton Rohrscheib. I'm a 52 year old entrepreneur w/ ADHD, OCD (and now AARP) that refuses to grow up as I grow old. I have collaborated and invested in hundreds of projects throughout my career in multiple industries such as; technology, healthcare, and agriculture. I also have 25 years experience in the marketing industry as a co-founder of an award-winning advertising agency. I will undoubtedly cover a wide variety of topics on my podcast while sharing some really crazy stories and situations that I've been fortunate to witness firsthand. I also have a book coming out in 2025 titled, "Mistakes were Made"

Please Drop Your Questions or CommentsCancel reply

Let’s Connect

  • Email
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter

Recent Updates

  • EP:032 – Cotton Rohrscheib & Diana DeHart
  • Challenges & Opportunities Going into 2025
  • Find us at the 2025 Arkansas Women in Agriculture Conference in Hot Springs, Arkansas
  • Be Sure to Checkout FBN’s Farmers First™  Crop Nutrition & Adjuvant Lineup for 2025
  • What we all need in Dark Times…

Blog Categories

  • Blog (419)
  • Entertainment (376)
  • Faith & Family (147)
  • Farm & Business (288)
  • Health & Wellness (33)
  • Marketing & Tech (584)
  • Podcasts (31)
  • Urban Farming (20)
  • Weekend Projects (1)

Listen & Subscribe

Blog Archives

Join the Cotton Club!

 

Content Copyright: 2001-2025
Cotton Rohrscheib | Rohrscheib Capital