User Management Code

  Home arrow User Management Code arrow Simple and Easy Security
USER MANAGEMENT CODE

Simple and Easy Security
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2002-11-06

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    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>&nbsp; <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>&nbsp; <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>&nbsp;</font></td><td width=5 align=center valign=middle><font size=-2 face=Tahoma, Verdana, Arial>&nbsp;</font></td><td align=left valign=middle><font size=-2 face=Tahoma, Verdana, Arial>&nbsp; <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

    blog comments powered by Disqus

    USER MANAGEMENT CODE ARTICLES

    - XCRYPT v1.0b
    - DB_eSession class stores sessions in a MySQL...
    - Ever Changing Dynamic Passcode Code
    - phpAutoMembersArea - create own members area
    - Azura Signup 2.5
    - Azura Signup 2.0
    - Azura Signup
    - Flexcustomer
    - PHP Quicksite 2.0
    - PHP Quicksite 1.0
    - random string generator (key generator)
    - Example Login system
    - Simple and Easy Security
    - Basic Security
    - UMA - User Management and Authentication

    Developer Shed Affiliates

     



    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap