Overview

HTTPS SSH

phpDBauth

Version 2.6.0
Download https://bitbucket.org/viharm/phpdbauth/downloads/?tab=tags
Issues https://bitbucket.org/viharm/phpdbauth/issues
License Modified BSD (3-clause)
Language PHP

phpDBauth is a PHP library for looking up users in a database table field. It returns a boolean value if the user if found, if supplied with the correct parameters. If not found, the user is added to the same database table field; and a specified default role is applied to a specified role column in the same table.

Installation

Pre-requisites

  • PHP 5+ with MySQL support (either PDO or mysqli or mysql)
  • Standard web framework (web server, etc.)
  • Database server (currently only MySQL is supported)

Download

Archive

Get the release archives from the downloaded link provided at the top of this page.

Composer

From v2.5.0 onwards, phpDBauth is enabled for Composer, and is available on Packagist as viharm/php-db-auth. You may either install it standalone or include it in your project as a dependency.

Standalone

php compser.phar create-project viharm/php-db-auth phpDBauth

The above command will install phpDBauth in a sub-directory phpDBauth of the current working directory.

Dependency

To make Composer automatically install phpDBauth as a dependency include the following in your composer.json

{
    "require": {
    "viharm/php-db-auth": "^2.5.0"
    }
}

If you would prefer to install this dependency in a custom directory, please include the following in your composer.json

{
    "require": {
    "php": ">=5.3.0",
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "viharm/php-db-auth": "^2.5.0"
    },
 "config": {
    "vendor-dir": "Lib"
  },
  "extra": {
    "installer-paths": {
      "./Lib/php-db-auth": ["viharm/php-db-auth"]
    }
}

In the above example, mnsami's Composer Custom Directory Installer is used to customise the install path.

* `Lib` is the sub-directory for plugins
* `./Lib/phpDBauth` is the install path for *phpDBauth*, relative to your project directory (`composer.json` location)

Clone

Clone repository.

git clone --recurse-submodules \
https://viharm@bitbucket.org/viharm/phpdbauth.git

Remember to clone recursively (--recurse-submodules) to ensure cloning the submodules.

Deploy

Extract the contents of the archive into the required directory. You should have a directory structure like the following:

  • <APPLICATION>/db/README.md
  • <APPLICATION>/db/LICENSE.txt
  • <APPLICATION>/db/VERSION.txt
  • <APPLICATION>/db/phpdbauth.php
  • <APPLICATION>/db/Lib/
  • <APPLICATION>/db/Lib/phpKhelper/
  • <APPLICATION>/db/Lib/phpKhelper/phpKhelper.lib.inc.php
  • <APPLICATION>/db/Lib/phpKhelper/...

Usage

This library requires a precise set of parameters supplied as associative arrays to work properly.

Use in your code by passing the correct parameters/arrays to the core function

$LookupResult = fn__Database_Verify (
  $Request ,
  $Table ,
  $MysqlExtension ,
  $Database ,
  $Database_Connection
) ;

Input parameters/arguments

Request

Search requests are packaged in a 'Request' associative array of strings

$Request = array (
  'ky_UserKeyword' => 'username' ,
  'ky_UserPassword' => 'password' ,
  'ky_GroupKeyword' => 'usersgroup' ,
) ;
Username

$Request['ky_UserKeyword'] specifies the username to be looked up.

This field is required.

Password

$Request['ky_UserPassword'] is a password field for compatibility with other scripts.

This field is not required by the script and will be removed from future versions.

It is recommended that a NULL value be provided.

Group

$Request['ky_GroupKeyword'] is a group field for compatibility with other scripts.

This field is not required by the script and will be removed from future versions.

It is recommended that a NULL value be provided.

Table settings

$Table = array (
  "key__Table_Name"             => "Users" ,
  "key__Table_ColumnUsername"   => "Username" ,
  "key__Table_ColumnRole"       => "Role" ,
  "key__Table_DefaultRoleValue" => "READ ONLY"
) ;

The key names must be exactly as specified above.

MySQL extension type

This parameter defines the type of database extension to be used

pdo-mysql
$MysqlExtension = 'pdo-mysql' ;

Uses the PHP PDO extension for MySQL connectivity.

mysqli
$MysqlExtension = 'mysqli' ;

Uses the PHP mysqli extension.

mysql
$MysqlExtension = 'mysql' ;

Uses the PHP mysql extension.

Database parameters

$Database = array (
  "key__Database_Host"     => "localhost" ,
  "key__Database_Port"     => 3306 ,
  "key__Database_Name"     => "databasename" ,
  "key__Database_User"     => "databaseusername" ,
  "key__Database_Password" => "databasepassword" ,
) ;

Database connection object

$Database_Connection = $ExistingDb->Connection();
$ExistingDb->Connection = mysqli_connect (
  $Database [ "key__Database_Host" ] ,
  $Database [ "key__Database_User" ] ,
  $Database [ "key__Database_Password"] ,
  $Database [ "key__Database_Name" ] ,
  $Database [ "key__Database_Port" ]
) ;

Response

The core function returns and associative array of three boolean elements.

$Result = array (
  "key__Database_Connection" => FALSE ,
  "key__Database_UserFound"  => FALSE ,
  "key__Database_UserAdded"  => FALSE
) ;

Database connection result

$Result['key__Database_Connection'] is set to TRUE if the database connection (if required) was succesful.

User lookup

$Result['key__Database_UserFound'] is set to TRUE if the requested user is found in the specified database table field.

User addition

$Result['key__Database_UserAdded'] is set to TRUE if, following a failure to find him/her, the requested user was added to specified database table field.

Known issues

Known issues are included in the issues deck, link to which is provided at the top of this page.

Support

Debugging can be enabled by setting boolean $GLOBALS['bl_DebugSwitch'] to TRUE.

$GLOBALS['bl_DebugSwitch'] = TRUE ;

For issues, queries, suggestions and comments please create an issue (link at the top of this page).

Contribute

Please feel free to clone/fork and contribute via pull requests. Bitcoin donations also welcome at 1MtGwgawfGjJc4Ln7KA7Re6mJrAo6pGfjm.

Please make contact for more information.

Development environment

Platform and software stack known to be compatible:

  • Server OS
    • Debian Wheezy
    • Debian Jessie
    • Ubuntu 14.04
  • Client OS
    • Debian Wheezy
    • Debian Jessie
    • Windows 7
  • Web servers
    • Apache 2.2
    • Apache 2.4
  • PHP
    • 5.4
    • 5.5
    • 5.6
  • MySQL
    • 5.4
    • 5.5

License

Licensed under the modified BSD (3-clause) license.

A copy of the license is available...

Credits

Tools

Kint

Kint debugging library (https://kint-php.github.io/kint/). Licensed under the MIT license

Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)

Utilities

Codiad

Codiad web based IDE (https://github.com/Codiad/Codiad). Licensed under a MIT-style license.

Copyright (c) Codiad & Kent Safranski (codiad.com)

CodeGit

CodeGit Git plugin for Codiad (https://github.com/Andr3as/Codiad-CodeGit), used under a MIT-style license.

Copyright (c) Andr3as andranode@gmail.com

Ungit

Ungit client for Git (https://github.com/FredrikNoren/ungit) used under the MIT license

Copyright (C) Fredrik Norén

SmartGit

SmartGit client for Git (http://www.syntevo.com/smartgit/) used under SOFTWARE Non-Commercial License

Copyright by syntevo GmbH

jEdit

jEdit text editor (http://www.jedit.org/), used under the GNU GPL v2.

Copyright (C) jEdit authors.

BitBucket

Hosted by BitBucket code repository (www.bitbucket.org).

Powered by Atlassian (www.atlassian.com).

Composer

Dependency management provided by Composer (https://getcomposer.org).

Packagist

Composer package hosting provided by Packagist (https://packagist.org).

Testing

  • Radoslav Chovan