Overview

Namespaces

  • CJPGDK
    • PhpHttpAuth
      • Database
      • Hash
  • PHP

Classes

  • HttpAuth
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Class HttpAuth

PHP Library to make use of HTTP Authentication

CJPGDK\PhpHttpAuth\HttpAuth uses CJPGDK\PhpHttpAuth\Hash\Bcrypt, CJPGDK\PhpHttpAuth\Hash\Sha, CJPGDK\PhpHttpAuth\Hash\Apr1Md5
Namespace: CJPGDK\PhpHttpAuth
Package: CJPGDK\PhpHttpAuth
Copyright: (c) 2017, Christian M. Jensen cmj@cjpg.dk
License: The MIT License
Author: Christian M. Jensen cmj@cjpg.dk
Version: 1.0.0
Located at src/CJPGDK/PhpHttpAuth/HttpAuth.php
Methods summary
public
# __construct( CJPGDK\PhpHttpAuth\Database\DB $db = null )
public
# updateUser( string $name, string $passwd, boolean $save = false )

Update a users password.

Update a users password.

Parameters

$name
$passwd
$save
save changes to users backend
public
# deleteUser( string $name, boolean $save = false )

Delete a user from the users store

Delete a user from the users store

Parameters

$name
$save
save changes to users backend
public array
# getUsers( )

Get all users. (paswords are replaced with 'hidden')

Get all users. (paswords are replaced with 'hidden')

Returns

array
public static CJPGDK\PhpHttpAuth\HttpAuth
# getInstance( boolean $new = false, CJPGDK\PhpHttpAuth\Database\DB $db = null )

Get an instance of this class, and cache the object for future use.

Get an instance of this class, and cache the object for future use.

Parameters

$new
get as new instance or use existing.
$db

Returns

CJPGDK\PhpHttpAuth\HttpAuth
public
# setUsersFile( string $htpasswd )

set the full/relative path to htpasswd file, to use for authenticating users.

set the full/relative path to htpasswd file, to use for authenticating users.

Parameters

$htpasswd
public
# savePasswdFile( string $htpasswd = null )

Save all users to a password file.

Save all users to a password file.

Parameters

$htpasswd
[optional] path to password file
public
# appendUsers( array $users, boolean $save = false )

Append new users to the existing users table.

Append new users to the existing users table.

Parameters

$users
$save
save changes to users backend
public
# setUsers( array $users, boolean $save = false )

Set available users

Set available users

Parameters

$users
$save
save changes to users backend
public
# addUser( string $name, string $passwd, boolean $save = false )

Add a new user to the user table

Add a new user to the user table

Parameters

$name
$passwd
$save
save changes to users backend
protected string
# getUserPassword( string $username )

Get password for a user.

Get password for a user.

Parameters

$username

Returns

string
protected string
# getUsername( string $username )

Get the username of username if it exists in the user table. if no user is found returns an empty string

Get the username of username if it exists in the user table. if no user is found returns an empty string

Parameters

$username

Returns

string
public string
# whoAmI( )

get the username of the currently authenticated user

get the username of the currently authenticated user

Returns

string
public boolean
# hasValidCredentials( string $realm = 'Restricted area' )

Check if the visitor has send us some credentials

Check if the visitor has send us some credentials

Parameters

$realm
[optional]

Returns

boolean
public boolean
# authBasic( string $realm = 'Restricted area', string $message = 'Restricted area' )

Send headers requesting http auth basic, if the user hits cancel the text from $message will be displayed and the script dies

Send headers requesting http auth basic, if the user hits cancel the text from $message will be displayed and the script dies

Parameters

$realm
[optional] the realm the visitor need valid credentials to roam
$message
[optional] message to show the visitor if the visitor did not authticate

Returns

boolean
true if the visitor has used a valid authtication
public
# requestReAuthBasic( string $realm = 'Restricted area', string $message = 'Restricted area' )

request the visitor to authenticate again, ignoring the current user and password set

request the visitor to authenticate again, ignoring the current user and password set

Parameters

$realm
[optional] the realm the visitor need valid credentials to roam
$message
[optional]
public boolean
# matchPasswd( string $plain, string $hash, boolean $allowPlain = false )

check the password matches APR1-MD5, SHA1, Bcrypt or if allowed plain text

check the password matches APR1-MD5, SHA1, Bcrypt or if allowed plain text

Parameters

$plain
plain text password
$hash
hashed password.
$allowPlain
[optional] allow plain text passwords.

Returns

boolean
public boolean
# validateAuthDigestResponse( string $realm = 'Restricted area', array|null $data = null )

Validate an wuthentication request using auth digest

Validate an wuthentication request using auth digest

Parameters

$realm
the realm the visitor need valid credentials to roam
$data
[optional]

Returns

boolean
public boolean|array
# authDigestGetUserDetails( )

Get user details from auth digest request

Get user details from auth digest request

Returns

boolean|array
returns boolean false on authentication error
public
# requestReAuthDigest( string $realm = 'Restricted area', string $message = 'Restricted area' )

Send headers requesting http auth digest, if the user hits cancel the text from $message will be displayed and the script dies

Send headers requesting http auth digest, if the user hits cancel the text from $message will be displayed and the script dies

Parameters

$realm
[optional] the realm the visitor need valid credentials to roam
$message
[optional]

Returns


No value is returned.
public
# authDigest( string $realm = 'Restricted area', string $message = 'Restricted area' )

Send headers requesting http auth digest, if the user hits cancel the tekst from $message will be displayed and the script dies

Send headers requesting http auth digest, if the user hits cancel the tekst from $message will be displayed and the script dies

Parameters

$realm
[optional] the realm the visitor need valid credentials to roam
$message
[optional]

Returns


No value is returned.
public mixed
# getServerVariableValue( string $name, mixed $default = null )

Get the value of _SERVER variable by name

Get the value of _SERVER variable by name

Parameters

$name
a name to find in the server variable.
$default
[optional] default value to return if server variable is not set

Returns

mixed
public
# send401Unauthorized( )

Send a 401 Unauthorized header

Send a 401 Unauthorized header

Returns


No value is returned.
public
# sendHeader( string $string, boolean $replace = true, integer $http_response_code = null )

Send a raw HTTP header

Send a raw HTTP header

Parameters

$string
The header string.
$replace
[optional]
$http_response_code
[optional]

Returns


No value is returned.

Link

http://php.net/manual/en/function.header.php
Methods used from CJPGDK\PhpHttpAuth\Hash\Bcrypt
createUserBcrypt(), getBcryptHash(), getBcryptHtpasswdRow(), matchBcryptHash()
Methods used from CJPGDK\PhpHttpAuth\Hash\Sha
createUserSha(), getShaHash(), getShaHtpasswdRow(), matchShaHash()
Methods used from CJPGDK\PhpHttpAuth\Hash\Apr1Md5
createUserApr1Md5(), getApr1Md5Hash(), getApr1Md5HtpasswdRow(), matchApr1Md5Hash()
Properties summary
public boolean $allowPlainPassword

Allow login by plain text passwords

Allow login by plain text passwords

# false
PhpHttpAuth API documentation generated by ApiGen