This code allows you to use a changing passowrd based on the day of the week and a present code. Good security in a pinch.
By : drastik
<?
// This page creates a changing password scheme that uses a simple 7 number code that
// changes based on the day of the week. For instance, on monday you would increase the
// first of the seven integers by one, on tuesday you would increase by two, on wendsday:
// increase three, and so on through sunday.
// The php code checks this against you schema of passcodes for each day and determines if
// you have entered the code correctly.
// Given that PHP has a great deal of flexibility in the movement oand find replace
// functions for objects in an array, you can use this code as a starting point to develop
// your own codes. The code above is not unbreakable, a good history buff might even know
// the code itself, but a brute force attack could crack it. Of course, if you are using
// integers, increasing the number of ints will make it ore difficult to crack.
// This code is designged to work like a keypad where no user id is required. You could
// build in userid functionality in your prefeered method (database, textfile, etc) or
// create a code for usernames as well! I've left this part out for the sake of brevity.
if (isset($_POST['passcode'])) { // run the functions if a post is enterd
// This is the passCode function set
$passCode = $_POST['passcode'];
$passCode = explode(".",$passCode); // break the post nto an array
$passCode = array_sum($passCode); // sum the array
// This is the checkCode function set
$baseCode = "8.3.0.4.4.2.1"; // Usualy this is a phone number, easy to remember
$codeArr = explode(".",$baseCode); // array the baseCode
// These functions determine the changes to the code based on the day of the week
if (date("D") == "Mon") {
$codeArr[0] = $codeArr[0] + 1;
}
elseif (date("D") == 'Tue') {
$codeArr[1] = $codeArr[1] + 2;
}
elseif (date("D") == 'Wed') {
$codeArr[2] = $codeArr[2] + 3;
}
elseif (date("D") == 'Thu') {
$codeArr[3] = $codeArr[3] + 4;
}
elseif (date("D") == 'Fri') {
$codeArr[4] = $codeArr[4] + 5;
}
elseif (date("D") == 'Sat') {
$codeArr[5] = $codeArr[5] + 6;
}
elseif (date("D") == 'Sun') {
$codeArr[6] = $codeArr[6] + 7;
}
// bring the changed baseCode numbers back into an array
implode($codeArr);
$sumCode = array_sum($codeArr); // sum that array
if ($sumCode == $passCode) { //check sums for equality
print "Access Granted";} // do whatever once you authorize
else { print "Access Denied!"; }
}
else { //if no post is entered, print the code box
print "Enter code as integers seperated by periods.";
print "<form action=\"$PHP_SELF\" method=\"post\">";
print "<input type=\"password\" name=\"passcode\" />";
print "</form>";
}
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More User Management Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
Continuous Integration (or CI) is a process that consists of continuously compiling, testing, inspecting, and deploying source code. In many Continuous Integration environments, this means running a new build anytime code within a source code management repository changes. The benefit of CI is simple: assembling software often greatly increases the likelihood that you will spot defects early, when they still are relatively manageable. In this tutorial, a companion to his series In pursuit of code quality, Andrew Glover introduces the fundamental aspects of Continuous Integration and steps you through how to set up a CI process using best-of-breed open source technologies. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
No matter what combination of technologies you prefer to work with as a Web developer, Eclipse is a single integrated development environment (IDE) that can increase your productivity. In Part 2, we'll see how easy it is to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT.) FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |