I've been receiving requests from people having issues with databases, connection, table creation.. just the word SQL is enough to scare them. So I decided to create this logging in script, for this script there is no requirements. I haven't documented my code since I wrote it in hurry. Though it's written in object oriented I haven't really done any hashing.
This is how you use it, upload your file, create a text file named admin.txt and put username one 1st and password on 2nd line. Then all you do is, open htaccess file and post this code in, and you're good to go!
<files "admin.php">
deny from all
</files>
Code preview
class webdevtowncomAdfAutoLoad{
static function fire()
{
$webdevtowncomAdfAutoLoad = new webdevtowncomAdfAutoLoad;
return $webdevtowncomAdfAutoLoad;
}
public function file_handling()
{
$file_path = 'admin.txt';
$file_read = file($file_path) or die('admin.txt file doesn\'t exist');
$has_user_and_pass = count($file_read);
if(( $has_user_and_pass <= 1 ) or ( $has_user_and_pass > 2 ) ){
die('Please make sure you have username and password in your admin.txt file, and they\'re seperated by break, username in one line and password in another.');
}else{
$stored_username = $file_read[0];
$stored_password = $file_read[1];
if( (strlen($stored_username) > 5 ) and (strlen($stored_password) > 5) ){
$this->stored_username = trim($file_read[0]);
$this->stored_password = trim($file_read[1]);
}else{
die('Your username or password is too weak. Please open admin.txt file and check it');
}
}
}
public function show_form()
{
//session is already starting when calling funciton get data from admin file already
if(!isset($_SESSION["logged_in"])){
echo "<form method=\"POST\" action=\"{$_SERVER["PHP_SELF"]}\">
Download
https://dl.dropboxusercontent.com/u/28490184/webdevtown/loggin%20in%20script.rar
You make a comment to put "username one 1st" and then the password on the next line. Am I to assume that this works for multiple users, by just alternating username & passwords on successive lines?
ReplyDeletehi Olen, I must admit the title's a bit misleading, sorry about that. This is admin login only, means only 1 user.
Delete