Simple and Easy Security, with txt file as user list and password. Easy to manage and adapt to your website. It cost free.
By : hermawan
<?php
/************************************************\
* Function Name : Security Made Easy *
* Creator : Hermawan Haryanto *
* Email : hermawan@codewalkers.com *
* Website : http://hermawan.com *
* License : GPL (General Public License) *
\***********************************************/
session_start();
class security {
var $usernames = Array ();
var $passwords = Array ();
var $error;
function security () {
$this->setAccountFile ("security.txt");
}
function setAccountFile ($file) {
$fp = fopen ($file,"r");
$content = fread ($fp,filesize ($file));
$contents = explode("\n", $content);
for ($i=0;$i<count($contents);$i++) {
if (!$this->isempty($contents[$i])) {
$accounts = explode("|", $contents[$i]);
if (!$this->isempty($accounts[0])) {
$this->usernames[] = $this->decode($accounts[0]);
$this->passwords[] = $this->decode($accounts[1]);
}
}
}
}
function secureme () {
global $_POST;
$forms = $_POST;
if (count($forms)<1) {
if (!$_SESSION || trim($_SESSION["loggedin"])=="") {
$this->showloginform();
exit();
}
} else {
if ($this->isempty($forms["username"])) $this->seterror("<li>Username is empty!</li>");
if ($this->isempty($forms["password"])) $this->seterror("<li>Password is empty!</li>");
if ($this->isempty($this->error)) {
if (in_array($forms["username"], $this->usernames)) {
for ($i=0;$i<count($this->usernames);$i++) {
if ($forms["username"]==$this->usernames[$i]) {
if ($forms["password"]!=$this->passwords[$i]) $this->seterror("<li>Username seems right but the password is wrong!</li>");
}
}
} else {
$this->seterror("<li>Username is not known!</li>");
}
}
if ($this->isempty($this->error)) {
$_SESSION["loggedin"] = "true";
Header("Location:".$forms["ref"]);
exit();
} else {
$this->showerror();
$this->showloginform();
exit();
}
}
}
function seterror($str) {
$this->error .= $str;
}
function showerror() {
print "<center><b>Error:</b><font color=#FF0000>$this->error</font></center>";
}
function isempty ($str) {
if (trim($str)=="") return true;
else return false;
}
function showloginform () {
print "<body><table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td align=center valign=middle><table width=250 border=0 cellpadding=4 cellspacing=1 bgcolor=#EEEEEE><tr><td align=center valign=middle><font size=-1 face=Tahoma, Verdana, Arial><strong>User Authentication</strong></font></td></tr><tr><td bgcolor=#FFFFFF><table width=100% border=0 cellspacing=0 cellpadding=2><form method=post><input type=hidden name=ref value=".$_SERVER["PHP_SELF"]."><tr><td width=75 align=right valign=middle><font size=-2 face=Tahoma, Verdana, Arial><strong>Username</strong></font></td><td width=5 align=center valign=middle><font size=-2 face=Tahoma, Verdana, Arial>:</font></td><td align=left valign=middle><font size=-2 face=Tahoma, Verdana, Arial> <input name=username type=text size=22></font></td></tr><tr><td width=75 align=right valign=middle><font size=-2 face=Tahoma, Verdana, Arial><strong>Password</strong></font></td><td width=5 align=center valign=middle><font size=-2 face=Tahoma, Verdana, Arial>:</font></td><td align=left valign=middle><font size=-2 face=Tahoma, Verdana, Arial> <input name=password type=password size=22></font></td></tr><tr><td width=75 align=right valign=middle><font size=-2 face=Tahoma, Verdana, Arial> </font></td><td width=5 align=center valign=middle><font size=-2 face=Tahoma, Verdana, Arial> </font></td><td align=left valign=middle><font size=-2 face=Tahoma, Verdana, Arial> <input name=action type=submit id=action value=LOGIN></font></td></tr></form></table></td></tr></table></td></tr></table></body>";
}
function encode ($str) {
return base64_encode ($str);
}
function decode ($str) {
return base64_decode ($str);
}
};
if (eregi("security.php", $_SERVER["PHP_SELF"])) {
$act = $_GET["act"];
switch ($act) {
case "encode" :
if ($_GET["str"]) {
$s = new security;
print $s->encode($str);
break;
} else {
Header("Location: http://www.dekap.com");
break;
}
case "logout" :
session_destroy();
Header("Location:".$_SERVER["HTTP_REFERER"]);
break;
default :
Header("Location: http://www.dekap.com");
break;
}
}
?>
Click to
Download File| 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!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |