Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcAuthenticationHtpasswdFilter

Authentication::ezcAuthenticationHtpasswdFilter

Class ezcAuthenticationHtpasswdFilter

Filter to authenticate against an Unix htpasswd file.

It supports files created with the htpasswd command options -m (MD5 encryption - different than the PHP md5() function) -d (CRYPT encryption) -s (SHA encryption) -p (plain text)

The encryption used for the password field in the file will be detected automatically.

The password property can be specified as plain text or in encrypted form, depending on the option 'plain' in the ezcAuthenticationHtpasswdOptions object used as options.

Example:

  1.  $credentials = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' );
  2.  $authentication = new ezcAuthentication( $credentials );
  3.  $authentication->session = new ezcAuthenticationSession();
  4.  $authentication->addFilter( new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd' ) );
  5.  // add other filters if needed
  6.  if ( !$authentication->run() )
  7.  {
  8.      // authentication did not succeed, so inform the user
  9.      $status = $authentication->getStatus();
  10.      $err = array(
  11.              'ezcAuthenticationHtpasswdFilter' => array(
  12.                  ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
  13.                  ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
  14.                  )
  15.              );
  16.      foreach ( $status as $line )
  17.      {
  18.          list( $key, $value ) = each( $line );
  19.          echo $err[$key][$value] . "\n";
  20.      }
  21.  }
  22.  else
  23.  {
  24.      // authentication succeeded, so allow the user to see his content
  25.  }

Source for this file: /Authentication/src/filters/htpasswd/htpasswd_filter.php

ezcAuthenticationFilter
   |
   --ezcAuthenticationHtpasswdFilter
Version:   //autogen//

Constants

STATUS_PASSWORD_INCORRECT = 2 Password is incorrect.
STATUS_USERNAME_INCORRECT = 1 Username is not found in the htpasswd file.

Inherited Constants

From ezcAuthenticationFilter:
ezcAuthenticationFilter::STATUS_OK    Successful authentication.

Properties

string read/write $file
The path and file name of the htpasswd file to use.

Inherited Member Variables

From ezcAuthenticationFilter
protected ezcAuthenticationFilter::$options

Method Summary

public ezcAuthenticationHtpasswdFilter __construct( $file , [ $options = null] )
Creates a new object of this class.
public int run( $credentials )
Runs the filter and returns a status code when finished.

Inherited Methods

From ezcAuthenticationFilter
public ezcAuthenticationFilterOptions ezcAuthenticationFilter::getOptions()
Returns the options of this class.
public abstract int ezcAuthenticationFilter::run()
Runs the filter and returns a status code when finished.
public void ezcAuthenticationFilter::setOptions()
Sets the options of this class to $options.

Methods

__construct

ezcAuthenticationHtpasswdFilter __construct( string $file , [ezcAuthenticationHtpasswdOptions $options = null] )

Creates a new object of this class.

Parameters:
Name Type Description
$file string The path and file name of the htpasswd file to use
$options ezcAuthenticationHtpasswdOptions Options for this class
Exceptions:
Type Description
ezcBaseValueException if the value provided is not correct for the property $file
ezcBaseFileNotFoundException if $file does not exist
ezcBaseFilePermissionException if $file cannot be opened for reading

run

int run( ezcAuthenticationPasswordCredentials $credentials )

Runs the filter and returns a status code when finished.

Parameters:
Name Type Description
$credentials ezcAuthenticationPasswordCredentials Authentication credentials
Redefinition of:
Method Description
ezcAuthenticationFilter::run() Runs the filter and returns a status code when finished.
Documentation generated by phpDocumentor 1.4.3