Simplify your business
Monday, 13 October 2008 11:00 pm

More secure admin logins

Monday, 15 January 2007  

A good way to improve the security of your website administration login is to restrict the input field length for the username and password to something reasonable. This is commonly done with the “maxlength” attribute in HTML:

<input type="text" name="username" value="" size="30" maxlength="30" />
<input type="password" name="password" value="" size="30" maxlength="30" />

As an added precaution, your login form should also make sure it strips any surplus characters, once the data has been submitted. If your server-side language is PHP, you could use the substr() function to restrict the input data to match the “maxlength” attribute above:

if (isset($_POST['username'])) {
   $username = substr(trim($_POST['username']), 0, 30);
   $username = mysql_real_escape_string($username);
} else {
   $username = '';
}
if (isset($_POST['password'])) {
   $password = substr(trim($_POST['password']), 0, 30);
   $password = mysql_real_escape_string($password);
} else {
   $password = '';
}

The restriction via substr() is especially important because it will help protect your website from the script kiddies as well.

Posted in HTML, PHP, Security, Tips, Usability by Ivan
Blinklist icon Del.iocio.us icon Furl icon Reddit icon Technorati icon Yahoo! icon

Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.