2017 © Pedro Peláez
 

library http-basic-auth

Simple HTTP basic auth that needs no framework

image

rikudou/http-basic-auth

Simple HTTP basic auth that needs no framework

  • Tuesday, May 16, 2017
  • by RikudouSage
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

HTTP Basic auth for php

This module does not require any framework and is really simple., (*1)

Installation

composer require rikudou/http-basic-auth, (*2)

Usage

<?php

use Rikudou\HttpBasicAuth;

// message displayed in standard browser window
$message = "Please input your username and password!"; 

// add the message to the object
$auth = new HttpBasicAuth($message);

// set the callback, it accepts two parameters, username and password and should
// return true (auth succeeded) or false (auth failed)
// in callback you can do pretty much everything, connect to your db, call classes, etc.
// the callback can be any callable (see http://php.net/manual/en/language.types.callable.php)
$auth->setCallback(function($username, $password) {
   if($username == "foo" && $password == "bar") {
     return true;
   }
   return false;
});

$result = $auth->auth();

if($result) { // auth succeeded

} else { // auth failed

}

The callback can be also set in the constructor:, (*3)

<?php

use Rikudou\HttpBasicAuth;

$auth = new HttpBasicAuth("Please, authorize", function($username, $password){
  return true;
});

The auth() method can throw exceptions when the callback is not supplied or it's not callable., (*4)

<?php

use Rikudou\HttpBasicAuth;

$auth = new HttpBasicAuth("Authorize");

try {
  $auth->auth();
} catch (Exception $exception) {
  var_dump($exception->getCode() == HttpBasicAuth::ERR_NO_CALLBACK); // true
}

$auth->setCallback(1); // invalid callback

try {
  $auth->auth();
} catch (Exception $exception) {
  var_dump($exception->getCode() == HttpBasicAuth::ERR_CALLBACK_NOT_CALLABLE); // true
}

The Versions

16/05 2017

dev-master

9999999-dev https://github.com/RikudouSage/php-http-basic-auth

Simple HTTP basic auth that needs no framework

  Sources   Download

WTFPL

by Dominik Chrástecký

auth http basic auth basic http basic auth http basic authentication basic authentication

16/05 2017

v1.0

1.0.0.0 https://github.com/RikudouSage/php-http-basic-auth

Simple HTTP basic auth that needs no framework

  Sources   Download

WTFPL

by Dominik Chrástecký

auth http basic