| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
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>"; } ?>
More User Management Code Articles |
| |
| |