PHP Classes

PHP Security One: Base class to authenticate an logged in users

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 167 All time: 8,878 This week: 146Up
Version License PHP version Categories
securityone 1.0.1GNU Lesser Genera...5PHP 5, User Management, Security
Description 

Author

This package provides a base class to authenticate an logged in users.

It can process the authentication of user that logs in with a user name and a password using callback functions to perform the credentials verification and user permission checks.

A sub-class can extend the base class to implement these verifications for instance against a real database of registered users.

Picture of Jorge Castro
  Performance   Level  
Name: Jorge Castro <contact>
Classes: 30 packages by
Country: Chile Chile
Age: 48
All time rank: 12743 in Chile Chile
Week rank: 94 Up1 in Chile Chile Up
Innovation award
Innovation award
Nominee: 14x

Winner: 2x

Example

<?php
include "../lib/SecurityOne.php";

use
eftec\SecurityOne;
// set securityone
$security=new SecurityOne();
$security->setLoginFn(
    function(
SecurityOne $sec) {
        if (
$sec->user=='admin' && $sec->equalPassword('admin')) {
           
// is an admin
           
$sec->fullName="Bob.Admin";
           
$sec->role='admin';
           
$sec->group=['admin','user','sysop'];
            return
true;
        }
        if (
$sec->user=='user' && $sec->equalPassword('user')) {
           
// is an admin
           
$sec->fullName="Bob.User";
           
$sec->role='user';
           
$sec->group=['user'];
            return
true;
        }
        return
false;
    });


$button=@$_POST['button'];
$message="";
$logged=false;

if (
$button) {
   
$logged=$security->login($_POST['user'],$_POST['password']);
   
$message=(!$logged)?"User {$_POST['user']} or password {$_POST['password']} incorrect":"";
}



if (!
$button || !$logged) {
   
?>
<form method="post">
        <h1>Use admin/admin or user/user to login</h1>
        <label for="user" style="display:inline-block; width:100px;">user:</label>
        <input type="text" id="user" name="user"/><br/>
        <label for="password" style="display:inline-block; width:100px;">password:</label>
        <input type="password" id="password" name="password"/><br/>
        <input type="submit" name="button" value="login"/><br/>
        <span style="color:red"><?=$message;?></span>
    </form>
    <?php
} else {
   
?>
<h1>User logged as <?=$security->fullName;?></h1>
    <a href="2.logged.php">go to 2 as any user</a>
    <a href="2.logged.admin.php">go to 2 as administrator</a>
    <a href="3.logout.php">go to 3 logout</a>
    <?php
}





Details

SecurityOne

It's a barebone security class written on PHP

Packagist Total Downloads [License]() [Maintenance]() [composer]() [php]() [php]() [Doc]()

Usage

You can check a full usage (for mysql) in

EFTEC/SecurityOneMysql

Versions

  • 2018-10-27 2.1 Some maintenance changes. Now serialize() and deserialize() are public and field extraFields is functiona.
  • 2018-10-11 2.0 We changed some fields. Now address and phone fields are part of extraFields.
  • 2018-09-29 1.6 added status and cookie.
  • 2018-09-22 1.4 added role
  • 2018-09-22 1.3 some fixes
  • 2018-09-22 1.0 First version

  Files folder image Files  
File Role Description
Files folder imageexamples (4 files)
Files folder imagelib (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file 1.basiclogin.php Example Example script
  Accessible without login Plain text file 2.logged.admin.php Example Example script
  Accessible without login Plain text file 2.logged.php Example Example script
  Accessible without login Plain text file 3.logout.php Example Example script

  Files folder image Files  /  lib  
File Role Description
  Plain text file SecurityOne.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:167
This week:0
All time:8,878
This week:146Up