Class File_Passwd_Authbasic

Description

Manipulate AuthUserFiles as used for HTTP Basic Authentication.

Usage Example:


1 $htp = &File_Passwd::factory('AuthBasic');
2 $htp->setMode('sha');
3 $htp->setFile('/www/mike/auth/.htpasswd');
4 $htp->setExePath('/usr/bin/htpasswd');
5 $htp->load();
6 $htp->addUser('mike', 'secret');
7 $htp->save();

NOTE: You usually need not set the full path to the htpasswd binary unless it's not in your $PATH. For use in safe_mode see "Limitations".

Output of listUser()

      array
       + user => crypted_passwd
       + user => crypted_passwd
 

Limitations:

If you have "safe_mode" enabled you only can use DES encryption for your passwords. NOTE: If you're additionally on Win32 you even cannot use this class. This behavior derives from the unusual implementiation of the Apache's htpasswd encryption.

Located in Program_Root/Passwd/Authbasic.php (line 73)

File_Passwd_Common
   |
   --File_Passwd_Authbasic
Method Summary
 File_Passwd_Authbasic File_Passwd_Authbasic ([string $file = '.htpasswd'])
 mixed addUser (string $user, string $pass)
 mixed changePasswd (string $user, string $pass)
 string getExePath ()
 string getMode ()
 array listModes ()
 mixed parse ()
 mixed save ()
 mixed setExePath (string $path_to_htp)
 mixed setMode (string $mode)
 mixed verifyPasswd (string $user, string $pass)
 void __construct ([string $file = '.htpasswd'])
Variables
Methods
Constructor File_Passwd_Authbasic (line 113)

Constructor

  • access: public
File_Passwd_Authbasic File_Passwd_Authbasic ([string $file = '.htpasswd'])
  • string $file: path to AuthUserFile
addUser (line 178)

Add an user

The username must start with an alphabetical character and must NOT contain any other characters than alphanumerics, the underline and dash.

Returns a PEAR_Error if:

  • user already exists
  • user contains illegal characters

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed addUser (string $user, string $pass)
  • string $user
  • string $pass
changePasswd (line 204)

Change the password of a certain user

This method in fact adds the user with the new password after deleting it.

Returns a PEAR_Error if:

  • user doesn't exists
  • user contains illegal characters

  • return: true on success or a PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed changePasswd (string $user, string $pass)
  • string $user: the user whose password should be changed
  • string $pass: the new plaintext password
getExePath (line 257)

Get path to htpasswd executable if supplied earlier

  • access: public
string getExePath ()
getMode (line 290)

Get actual encryption mode

  • access: public
string getMode ()
listModes (line 312)

Get supported encryption modes

   array
    + md5
    + sha
    + des
 

ATTN: DES encryption not available on Win32!

If you are on a Win32 plattform, the binary distribution of Apache's htpasswd executable doesn't support DES encryption.

  • access: public
array listModes ()
parse (line 377)

Parse the AuthUserFile

Returns a PEAR_Error if AuthUserFile has invalid format.

  • return: true on success or PEAR_error
  • access: public
  • throws: PEAR_Error
mixed parse ()

Redefinition of:
File_Passwd_Common::parse()
Parse the content of the file
save (line 154)

Apply changes and rewrite AuthUserFile

Returns a PEAR_Error if:

  • directory in which the file should reside couldn't be created
  • file couldn't be opened in write mode
  • file couldn't be locked exclusively
  • file couldn't be unlocked
  • file couldn't be closed

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed save ()

Redefinition of:
File_Passwd_Common::save()
Apply changes and rewrite passwd file
setExePath (line 276)

Set path to htpasswd executable

NOTE: You usually don't need to set the complete path to the htpasswd binary unless it is NOT in your PATH!

Returns a PEAR_Error if supplied path doesn't map to a file or is not equal to 'htpasswd'. That's just if you want to reset this property to the default value.

  • return: true on succes or a PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed setExePath (string $path_to_htp)
  • string $path_to_htp
setMode (line 333)

Set the encryption mode

You can choose one of md5, sha or des.

ATTN: DES encryption not available on Win32!

If you are on a Win32 plattform, the binary distribution of Apache's htpasswd executable doesn't support DES encryption.

Returns a PEAR_Error if a specific encryption mode is not supported.

  • return: true on succes or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed setMode (string $mode)
  • string $mode
verifyPasswd (line 231)

Verify password

ATTN: Not available with MD5 ecncryption!

If you use MD5 encryption you cannot verify your passwords. This depends on Apache's htpasswd binary, which uses a unusual format for MD5 passwords.

Returns a PEAR_Error if:

  • user doesn't exist
  • you try to verify MD5 passwords
  • an invalid encryption mode was supplied

  • return: true if passwords equal, false if they don't, or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed verifyPasswd (string $user, string $pass)
  • string $user: the user whose password should be verified
  • string $pass: the plaintext password to verify
__construct (line 126)

Constructor (ZE2)

Rewritten because DES encryption is not supportet by the Win32 htpasswd binary.

  • access: protected
void __construct ([string $file = '.htpasswd'])
  • string $file: path to AuthUserFile

Redefinition of:
File_Passwd_Common::__construct()
Constructor (ZE2)

Inherited Methods

Inherited From File_Passwd_Common

File_Passwd_Common::delUser()
File_Passwd_Common::getFile()
File_Passwd_Common::listUser()
File_Passwd_Common::load()
File_Passwd_Common::parse()
File_Passwd_Common::save()
File_Passwd_Common::setFile()
File_Passwd_Common::userExists()
File_Passwd_Common::_close()
File_Passwd_Common::_open()
File_Passwd_Common::_save()
File_Passwd_Common::__clone()
File_Passwd_Common::__construct()

Documention generated on Sat, 20 Sep 2003 16:14:41 +0200 by phpDocumentor 1.2.1