PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File Formats » File_Passwd » Manual

Package to manage passwd-style files

Introduction

Introduction

Introduction – New File_Passwd Facilities The new File_Passwd package provides facilities to manage many different kinds of password files. Currently supported password file formats: Unix, CVS, SMB, AuthUserFile, AuthDigestFile and custom formatted passwd files. Fileformat passwd-style means, the file has a format like this: user<delimiter>password The delimiting character is usually the colon. With the new File_Passwd_Custom class you can choose your delimiting character, but be aware that any column of your passwd file MUST NOT contain the delimiter!

File_Passwd

The File_Passwd class provides a factory for all special purpose classes, static authentication and common encryption methods.

File_Passwd Constants

File_Passwd Constants – Constants used by File_Passwd

Constants

Encryption Constants
Name Value Description
FILE_PASSWD_DES "des" DES encryption
FILE_PASSWD_MD5 "md5" MD5 encryption
FILE_PASSWD_SHA "sha" SHA encryption
FILE_PASSWD_NT "nt" NT hash
FILE_PASSWD_LM "lm" LM hash
FILE_PASSWD_PLAIN "plain" no encryption
Error Constants
Name Value Description
FILE_PASSWD_E_UNDEFINED 0 undefined - some seldom occuring errors
FILE_PASSWD_E_INVALID_FORMAT 1 passwd file has invalid format
FILE_PASSWD_E_INVALID_PROPERTY 2 an invalid (additional) property was supplied
FILE_PASSWD_E_INVALID_CHARS 3 parameter contains illegal chracters (usually only alphanumerics, the dash and underline are allowed)
FILE_PASSWD_E_INVALID_ENC_MODE 4 an invalid encryption mode was supplied (depending on the class actually used)
FILE_PASSWD_E_EXISTS_ALREADY 5 an entry (user, group, etc) to add exists already
FILE_PASSWD_E_EXISTS_NOT 6 an entry (user, group, etc) to delete/change doesn't exist
FILE_PASSWD_E_USER_NOT_IN_GROUP 7 the specified user is not in this certain group
FILE_PASSWD_E_USER_NOT_IN_REALM 8 the specified user is not in this certain realm
FILE_PASSWD_E_PARAM_MUST_BE_ARRAY 9 the supplied param must be of type array
FILE_PASSWD_E_METHOD_NOT_IMPLEMENTED 10 requested method was not implemented yet
FILE_PASSWD_E_DIR_NOT_CREATED 11 a certain directory couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED 12 passwd file couldn't be opened
FILE_PASSWD_E_FILE_NOT_LOCKED 13 passwd file couldn't be locked
FILE_PASSWD_E_FILE_NOT_UNLOCKED 14 passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED 15 passwd file couldn't be closed

File_Passwd::apiVersion

File_Passwd::apiVersion() – Get API version

Synopsis

require_once 'File/Passwd.php';

string File_Passwd::apiVersion ( )

Description

Returns API version of the File_Passwd package.

Return value

Returns string API version (currently 1.0.0).

Note

This function can be called statically.

File_Passwd::factory

File_Passwd::factory() – Factory for extensions

Synopsis

require_once 'File/Passwd.php';

object &File_Passwd::factory ( string $class )

Description

Load the desired worker class (extension).

Parameter

string $class

the desired extension of File_Passwd

Return value

Returns object File_Passwd extension or PEAR_Error on failure.

Note

This function should be called statically.

File_Passwd::staticAuth

File_Passwd::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd.php';

mixed File_Passwd::staticAuth ( string $type , string $file , string $user , string $pass , mixed $opt = '' )

Description

Static user autentication.

Though this approach should be reasonable fast, it is NOT with APR compatible MD5 encryption used for htpasswd style password files encrypted in MD5.

Generating one MD5 password takes about 0.25 seconds!

Depending on $type, $opt should be:

Parameter

string $type

Unix, Cvs, Smb, Authbasic or Authdigest

string $file

path to passwd file

string $user

the user to authenticate

string $pass

the plaintext password

mixed $opt
  • Smb:

    • nt | lm
  • Unix:

    • des | md5
  • Authbasic:

    • des | sha | md5
  • Authdigest:

    • the realm the user is in
  • Cvs:

    • n/a (empty)
  • Custom:

    • array of 2 elements: encryption function and delimiter

Return value

Returns TRUE if authenticated, FALSE if not, or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed /only if auth fails)
FILE_PASSWD_E_UNDEFINED if class/file couldn't be loaded
FILE_PASSWD_E_INVALID_ENC_MODE supplied encryption mode is not supported
FILE_PASSWD_E_USER_NOT_IN_REALM user doesn't exist in this realm (only File_Passwd_Authdigest)

Note

This function should be called statically.

File_Passwd_Common

Base class for worker class extensions.

Childs

Childs – Classes that extend File_Passwd_Common and their inherited methods

Child Classes

Classes that extend File_Passwd_Common
Class Summary
File_Passwd_Authbasic Manipulate AuthUserFiles as used for HTTP Basic Authentication.
File_Passwd_Authdigest Manipulate AuthDigestFiles as used for HTTP Digest Authentication.
File_Passwd_Cvs Manipulate CVS pserver passwd files.
File_Passwd_Smb Manipulate SMB server passwd files.
File_Passwd_Unix Manipulate standard Unix passwd files.
File_Passwd_Custom Manipulate custom formatted passwd files.

List of inherited Methods

Inherited methods from File_Passwd_Common
Method Name Summary
File_Passwd_Common::delUser() Delete a certain user
File_Passwd_Common::getFile() Get path of passwd file
File_Passwd_Common::listUser() List user
File_Passwd_Common::load() Loads the file
File_Passwd_Common::parse() Parse the content of the file
File_Passwd_Common::save() Apply changes and rewrite passwd file
File_Passwd_Common::setFile() Set path to passwd file
File_Passwd_Common::userExists() Check if a certain user already exists
File_Passwd_Common::_auth() Base method for File_Passwd::staticAuth()
File_Passwd_Common::_close() Closes a prior opened and locked file handle
File_Passwd_Common::_open() Opens a file, locks it exclusively and returns the filehandle
File_Passwd_Common::_save() Save the modified content to the passwd file

File_Passwd_Common::delUser

File_Passwd_Common::delUser() – Delete a certain user

Synopsis

mixed^File_Passwd_Common::delUser ( string $user )

Description

Delete a certain user.

Parameter

string $user

username

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist

Note

This function can not be called statically.

File_Passwd_Common::listUser

File_Passwd_Common::listUser() – List user

Synopsis

mixed File_Passwd_Common::listUser ( string $user = '' )

Description

List one user's properties or all users.

Parameter

string $user

the user to list or all users if empty

Return value

Returns array of user(s) or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS suer doesn't exist

Note

This function can not be called statically.

File_Passwd_Common::userExists

File_Passwd_Common::userExists() – Check if user exists

Synopsis

bool File_Passwd_Common::userExists ( string $user )

Description

Check if a certain user already exists.

Parameter

string $user

the name of the user to check if already exists

Return value

Returns boolean whether user already exists.

Note

This function can not be called statically.

File_Passwd_Common::getFile

File_Passwd_Common::getFile() – Get path of passwd file

Synopsis

string File_Passwd_Common::getFile ( )

Description

Get the path of the passwd file.

Return value

Returns string path of passwd file.

Note

This function can not be called statically.

File_Passwd_Common::setFile

File_Passwd_Common::setFile() – Set path to passwd file

Synopsis

void File_Passwd_Common::setFile ( string $file )

Description

Set path to passwd file.

Parameter

string $file

path to passwd file

Note

This function can not be called statically.

File_Passwd_Common::load

File_Passwd_Common::load() – Loads the file

Synopsis

mixed File_Passwd_Common::load ( )

Description

Loads the passwd file and calls the parse() method of the extending child class.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED the directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed
FILE_PASSWD_E_INVALID_FORMAT passwd file has invalid format

Note

This function can not be called statically.

File_Passwd_Common::parse

File_Passwd_Common::parse() – Parse the content of the file

Synopsis

object File_Passwd_Common::parse ( )

Description

This is kinda abstract method which only returns a PEAR_Error, so it is to be overwritten in the extending child class.

You must overwrite this method in your File_Passwd_* class.

(package developer related)

Return value

Returns object PEAR_Error FILE_PASSWD_E_METHOD_NOT_IMPLEMENTED.

Note

This function can not be called statically.

File_Passwd_Common::save

File_Passwd_Common::save() – Apply changes and rewrite passwd file

Synopsis

object File_Passwd_Common::save ( )

Description

This is kinda abstract method which only returns a PEAR_Error, so it is to be overwritten in the extending child class.

You must overwrite this method in your File_Passwd_* class.

(package developer related)

Return value

Returns object PEAR_Error FILE_PASSWD_E_METHOD_NOT_IMPLEMENTED.

Note

This function can not be called statically.

File_Passwd_Common::_auth

File_Passwd_Common::_auth() – Base method for File_Passwd::staticAuth()

Synopsis

mixed File_Passwd_Common::_auth ( string $file , string $id )

Description

Base method for File_Passwd_*::staticAuth()

(package developer related)

Parameter

string $file

path to passwd file

string $id

user_id to search for

Return value

Returns string line of passwd file containing $id, FALSE if $id wasn't found, or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed (only if auth fails)

Note

This function can not be called statically.

File_Passwd_Common::_open

File_Passwd_Common::_open() – Open a file

Synopsis

mixed &File_Passwd_Common::_open ( string $mode , mixed $file = null )

Description

Opens a file, locks it exclusively and returns the filehandle.

(package developer related)

Parameter

string $mode

the mode to open the file with

string $file

path to passwd file

Return value

Returns resource file handle or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED the directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in the desired mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked

Note

This function can not be called statically.

File_Passwd_Common::_close

File_Passwd_Common::_close() – Closes a prior opened and locked file handle

Synopsis

mixed File_Passwd_Common::_close ( resource &$file_handle )

Description

Closes a prior with File_Passwd_Common::_open() opened and locked file handle.

(package developer related)

Parameter

resource &$file_handle

the file handle to operate on

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Common::_save

File_Passwd_Common::_save() – Save the modified content to the passwd file

Synopsis

mixed File_Passwd_Common::_save ( string $content )

Description

Save content to file.

(package developer related)

Parameter

string $content

file content

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED the directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Common::__construct

File_Passwd_Common::__construct() – Constructor (ZE2)

Synopsis

object File_Passwd_Common::__construct ( string $file = 'passwd' )

Description

Implemented for Zend Engine 2 compatibility.

(package developer related)

Parameter

string $file

path to passwd file

Return value

Returns object File_Passwd_* - new instance of an File_Passwd_* object.

Note

This function can not be called statically.

File_Passwd_Custom

Manipulate custom formatted passwd files. (inherited methods)

File_Passwd_Custom::staticAuth

File_Passwd_Custom::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Custom.php';

mixed File_Passwd_Custom::staticAuth ( string $file , string $user , string $pass , array $opts )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

array $opts

A two element array containing the encryption function to use and the delimiting character: e.g. array('md5', '|')

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed (only if auth fails)

Note

This function should be called statically.

File_Passwd_Custom::File_Passwd_Custom

File_Passwd_Custom::File_Passwd_Custom() – Constructor

Synopsis

require_once 'File/Passwd/Custom.php';

object &new File_Passwd_custom ( string $file = 'passwd' )

Description

Initialize a new File_Passwd_Custom object with the specified path to passwd file.

Parameter

string $file

path to passwd file

Return value

Returns object File_Passwd_Custom.

Note

This function can not be called statically.

File_Passwd_Custom::parse

File_Passwd_Custom::parse() – Parse passwd file

Synopsis

mixed File_Passwd_Custom::parse ( )

Description

Parse the custom passwd file. (package developer related)

This usually happens in File_Passwd_Custom::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_INVALID_FORMAT, if passwd file has illegal format.

Note

This function can not be called statically.

File_Passwd_Custom::save

File_Passwd_Custom::save() – Save changes

Synopsis

mixed File_Passwd_Custom::save ( )

Description

Apply changes and rewrite passwd file.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Custom::addUser

File_Passwd_Custom::addUser() – Add an user

Synopsis

mixed File_Passwd_Custom::addUser ( string $user , string $pass , array $extra = array() )

Description

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

The username MUST NOT contain the custom delimiter!

If you use the 'name map' you should also use these naming in the supplied extra array, because your values would get mixed up if they are in the wrong order, which is always true if you DON'T use the 'name map'!

So be warned and USE the 'name map'!

Parameter

string $user

the name of the user to add

string $pass

the password of the user to add

array $extra

extra properties of user to add

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_ALREADY_EXISTS user already exists
FILE_PASSWD_E_INVALID_CHARS username contains illegal characters
FILE_PASSWD_E_INVALID_CHARS any of the extra proporties contains the delimiter
FILE_PASSWD_E_INVALID_ENC_MODE actual encryption mode is not supported
FILE_PASSWD_E_UNDEFINED if passwd file is shadowed

Note

This function can not be called statically.

File_Passwd_Custom::modUser

File_Passwd_Custom::modUser() – Modify user

Synopsis

mixed File_Passwd_Custom::modUser ( string $user , array $properties = array() )

Description

You shouldn't modify the password of the user with this method, use File_Passwd_Custom::changePasswd() instead.

You should use this method only if the 'name map' is used, too.

Parameter

string $user

the user to modify

array $properties

an associative array of properties to modify

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exists
FILE_PASSWD_E_INVALID_CHARS any of the extra properties contains the delimiter

See

See File_Passwd_Custom::useMap()

See File_Passwd_Custom::changePasswd()

Note

This function can not be called statically.

File_Passwd_Custom::changePasswd

File_Passwd_Custom::changePasswd() – Change password

Synopsis

mixed File_Passwd_Custom::changePasswd ( string $user , string $pass )

Description

Change the password of a certain user.

Parameter

string $user

the user whose password should be changed

string $pass

the new plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_INVALID_ENC_MODE actual encryption mode is not supported

Note

This function can not be called statically.

File_Passwd_Custom::verifyPasswd

File_Passwd_Custom::verifyPasswd() – Verify password

Synopsis

mixed File_Passwd_Custom::verifyPasswd ( string $user , string $pass )

Description

Verify the password of a certain user.

Parameter

string $user

the user whose password should be verified

string $pass

the password to verify

Return value

Returns TRUE if passwords equal, FALSE if they don't or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_INVALID_ENC_MODE actual encryption mode isn't supported

Note

This function can not be called statically.

File_Passwd_Custom::useMap

File_Passwd_Custom::useMap() – Whether to use the 'name map'

Synopsis

boolean File_Passwd_Custom::useMap ( boolean $bool = null )

Description

Whether to use the 'name map' of the extra properties or not.

You first must supply a 'name map' to use it.

Parameter

boolean $bool

whether to use the 'name map' or not

Return value

Returns boolean TRUE if you set a value, or the actual value if called without param.

See

See File_Passwd_Custom::getMap()

See File_Passwd_Custom::setMap()

Note

This function can not be called statically.

File_Passwd_Custom::getMap

File_Passwd_Custom::getMap() – Get 'name map'

Synopsis

array File_Passwd_Custom::getMap ( )

Description

Get the 'name map' which is used for the extra properties of the user.

Return value

Returns array 'name map'.

See

See File_Passwd_Custom::setMap()

See File_Passwd_Custom::useMap()

Note

This function can not be called statically.

File_Passwd_Custom::setMap

File_Passwd_Custom::setMap() – Set 'name map'

Synopsis

mixed File_Passwd_Custom::setMap ( mixed $map = array() )

Description

Set the 'name map' to use with the extra properties of the user.

This map is used for naming the associative array of the extra properties.

Parameter

array $map

the 'name map'

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_PARAM_MUST_BE_ARRAY, if the supplied 'name map' was not of type array.

See

See File_Passwd_Custom::useMap()

See File_Passwd_Custom::getMap()

Note

This function can not be called statically.

File_Passwd_Unix

Manipulate standard Unix passwd files. (inherited methods)

File_Passwd_Unix::staticAuth

File_Passwd_Unix::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Unix.php';

mixed File_Passwd_Unix::staticAuth ( string $file , string $user , string $pass , string $mode )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

string $mode

des or md5

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed (only if auth fails)

Note

This function should be called statically.

File_Passwd_Unix::File_Passwd_Unix

File_Passwd_Unix::File_Passwd_Unix() – Constructor

Synopsis

require_once 'File/Passwd/Unix.php';

object &new File_Passwd_Unix ( string $file = 'passwd' )

Description

Initialize a new File_Passwd_Unix object with the specified path to passwd file.

Parameter

string $file

path to passwd file

Return value

Returns object File_Passwd_Unix.

Note

This function can not be called statically.

File_Passwd_Unix::parse

File_Passwd_Unix::parse() – Parse passwd file

Synopsis

mixed File_Passwd_Unix::parse ( )

Description

Parse the unix passwd file. (package developer related)

This usually happens in File_Passwd_Unix::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_INVALID_FORMAT, if passwd file has illegal format.

Note

This function can not be called statically.

File_Passwd_Unix::save

File_Passwd_Unix::save() – Save changes

Synopsis

mixed File_Passwd_Unix::save ( )

Description

Apply changes and rewrite passwd file.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Unix::addUser

File_Passwd_Unix::addUser() – Add an user

Synopsis

mixed File_Passwd_Unix::addUser ( string $user , string $pass , array $extra = array() )

Description

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

If you use the 'name map' you should also use these naming in the supplied extra array, because your values would get mixed up if they are in the wrong order, which is always true if you DON'T use the 'name map'!

So be warned and USE the 'name map'!

If the passwd file is shadowed, the user will be added though, but with an 'x' as password, and a PEAR_Error will be returned, too.

Parameter

string $user

the name of the user to add

string $pass

the password of the user to add

array $extra

extra properties of user to add

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_ALREADY_EXISTS user already exists
FILE_PASSWD_E_INVALID_CHARS username contains illegal characters
FILE_PASSWD_E_INVALID_CHARS any of the extra proporties contains a colon
FILE_PASSWD_E_INVALID_ENC_MODE actual encryption mode is not supported
FILE_PASSWD_E_UNDEFINED if passwd file is shadowed

Note

This function can not be called statically.

File_Passwd_Unix::modUser

File_Passwd_Unix::modUser() – Modify user

Synopsis

mixed File_Passwd_Unix::modUser ( string $user , array $properties = array() )

Description

You shouldn't modify the password of the user with this method, use File_Passwd_Unix::changePasswd() instead.

You should use this method only if the 'name map' is used, too.

Parameter

string $user

the user to modify

array $properties

an associative array of properties to modify

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exists
FILE_PASSWD_E_INVALID_CHARS any of the extra properties contains a colon

See

See File_Passwd_Unix::useMap()

See File_Passwd_Unix::changePasswd()

Note

This function can not be called statically.

File_Passwd_Unix::changePasswd

File_Passwd_Unix::changePasswd() – Change password

Synopsis

mixed File_Passwd_Unix::changePasswd ( string $user , string $pass )

Description

Change the password of a certain user.

Parameter

string $user

the user whose password should be changed

string $pass

the new plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_INVALID_ENC_MODE actual encryption mode is not supported
FILE_PASSWD_UNDEFINED if passwd file is shadowed

Note

This function can not be called statically.

File_Passwd_Unix::verifyPasswd

File_Passwd_Unix::verifyPasswd() – Verify password

Synopsis

mixed File_Passwd_Unix::verifyPasswd ( string $user , string $pass )

Description

Verify the password of a certain user.

Parameter

string $user

the user whose password should be verified

string $pass

the password to verify

Return value

Returns TRUE if passwords equal, FALSE if they don't or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_INVALID_ENC_MODE actual encryption mode isn't spported

Note

This function can not be called statically.

File_Passwd_Unix::useMap

File_Passwd_Unix::useMap() – Whether to use the 'name map'

Synopsis

boolean File_Passwd_Unix::useMap ( boolean $bool = null )

Description

Whether to use the 'name map' of the extra properties or not.

Default Unix passwd files look like:
user:password:user_id:group_id:gecos:home_dir:shell

The default 'name map' for properties except user and password looks like:

If you want to change the naming of the standard map use File_Passwd_Unix::setMap().

Parameter

boolean $bool

whether to use the 'name map' or not

Return value

Returns boolean TRUE if you set a value, or the actual value if called without param.

See

See File_Passwd_Unix::getMap()

See File_Passwd_Unix::setMap()

Note

This function can not be called statically.

File_Passwd_Unix::getMap

File_Passwd_Unix::getMap() – Get 'name map'

Synopsis

array File_Passwd_Unix::getMap ( )

Description

Get the 'name map' which is used for the extra properties of the user.

Return value

Returns array 'name map'.

See

See File_Passwd_Unix::setMap()

See File_Passwd_Unix::useMap()

Note

This function can not be called statically.

File_Passwd_Unix::setMap

File_Passwd_Unix::setMap() – Set 'name map'

Synopsis

mixed File_Passwd_Unix::setMap ( mixed $map = array() )

Description

Set the 'name map' to use with the extra properties of the user.

This map is used for naming the associative array of the extra properties.

Parameter

array $map

the 'name map'

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_PARAM_MUST_BE_ARRAY, if the supplied 'name map' was not of type array.

See

See File_Passwd_Unix::useMap()

See File_Passwd_Unix::getMap()

Note

This function can not be called statically.

File_Passwd_Unix::getMode

File_Passwd_Unix::getMode() – Get actual encryption mode

Synopsis

string File_Passwd_Unix::getMode ( )

Description

Get actual encryption mode (des|md5).

Return value

Returns string actual encryption mode.

See

See File_Passwd_Unix::setMode()

See File_Passwd_Unix::listModes()

Note

This function can not be called statically.

File_Passwd_Unix::setMode

File_Passwd_Unix::setMode() – Set encryption mode

Synopsis

mixed File_Passwd_Unix::setMode ( string $mode )

Description

Set encryption mode to use.

Supported encryption modes are 'des' and 'md5'.

You can use the constants FILE_PASSWD_MD5 and FILE_PASSWD_DES for this purpose.

Parameter

string $mode

encryption mode to use

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_INVALID_ENC_MODE, if supplied encryption mode is not supported.

See

See File_Passwd_Unix::listModes()

See File_Passwd_Unix::getMode()

Note

This function can not be called statically.

File_Passwd_Unix::listModes

File_Passwd_Unix::listModes() – Get supported encryption modes

Synopsis

array File_Passwd_Unix::listModes ( )

Description

List the supported encryption modes.


<pre>
array
 + md5
 + des
</pre>

Return value

Returns array supported encryption modes.

See

See File_Passwd_Unix::getMode()

See File_Passwd_Unix::setMode()

Note

This function can not be called statically.

File_Passwd_Unix::isShadowed

File_Passwd_Unix::isShadowed() – Check if passwd file is shadowed

Synopsis

boolean File_Passwd_Unix::isShadowed ( )

Description

Check if the passwords of this passwd file are shadowed in another file.

Return value

Returns boolean whether passwords of this passwd file are shadowed in another file.

Note

This function can not be called statically.

File_Passwd_Unix::generatePassword

File_Passwd_Unix::generatePassword() – Generate password

Synopsis

mixed File_Passwd_Unix::generatePassword ( string $pass , string $mode = 'md5' , string $salt = null )

Description

Generate a "Un*x" style password.

The encryption mode can be of any type File_Passwd provides, although FILE_PASSWD_MD5 and FILE_PASSWD_DES are the most common.

Parameter

string $pass

the plaintext password to encrypt

string $mode

the encryption mode to use

string $salt

the salt to use for encryption (usually empty)

Return value

Returns string encrypted password, or PEAR_Error FILE_PASSWD_E_INVALID_ENC_MODE if encryption mode is not supported.

Example

File_Passwd_Unix::generatePassword()

<?php
require_once 'File/Passwd/Unix.php';
$pass = File_Passwd_Unix::generatePassword('secret', FILE_PASSWD_MD5);
?>

Note

This function should be called statically.

File_Passwd_Cvs

Manipulate CVS pserver passwd files. (inherited methods)

File_Passwd_Cvs::staticAuth

File_Passwd_Cvs::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Cvs.php';

mixed File_Passwd_Cvs::staticAuth ( string $file , string $user , string $pass )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed /only if auth fails)

Note

This function should be called statically.

File_Passwd_Cvs::File_Passwd_Cvs

File_Passwd_Cvs::File_Passwd_Cvs() – Constructor

Synopsis

require_once 'File/Passwd/Cvs.php';

object &new File_Passwd_Cvs ( mixed $file = 'passwd' )

Description

Initialize a new File_Passwd_Cvs object with the given path to passwd file.

Parameter

string $file

path to passwd file

Return value

Returns object File_Passwd_Cvs.

Note

This function can not be called statically.

File_Passwd_Cvs::parse

File_Passwd_Cvs::parse() – Parse file

Synopsis

mixed File_Passwd_Cvs::parse ( )

Description

Parse the CVS passwd file. (package developer related)

This usually happens in File_Passwd_Cvs::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_INVALID_FORMAT, if passwd file has invalid format.

Note

This function can not be called statically.

File_Passwd_Cvs::save

File_Passwd_Cvs::save() – Save changes

Synopsis

mixed File_Passwd_Cvs::save ( )

Description

Apply changes and rewrite CVS passwd file.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Cvs::addUser

File_Passwd_Cvs::addUser() – Add an user

Synopsis

mixed File_Passwd_Cvs::addUser ( string $user , string $pass , string $system_user = '' )

Description

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

Parameter

string $user

the name of the user to add

string $pass

the password of the user tot add

string $system_user

the systemuser this user maps to

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_ALREADY user already exists
FILE_PASSWD_E_INVALID_CHARS user or system_user contain illegal characters

Note

This function can not be called statically.

File_Passwd_Cvs::changeSysUser

File_Passwd_Cvs::changeSysUser() – Change syste user

Synopsis

mixed File_Passwd_Cvs::changeSysUser ( mixed $user , mixed $system )

Description

Change the corresponding system user of a certain cvs user.

Parameter

string $user

the user to change the system user for

string $system

the new system user name

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_INVALID_CHARS system user contains illegal characters

Note

This function can not be called statically.

File_Passwd_Cvs::changePasswd

File_Passwd_Cvs::changePasswd() – Change password

Synopsis

mixed File_Passwd_Cvs::changePasswd ( mixed $user , mixed $pass )

Description

Change the password of a certain user.

Parameter

string $user

the user whose password should be changed

string $pass

the new plaintext password

Return value

$return.success-pearerror;

Returns PEAR_Error FILE_PASSWD_E_EXISTS_ALREADY, if user already exists.

Note

This function can not be called statically.

File_Passwd_Cvs::verifyPasswd

File_Passwd_Cvs::verifyPasswd() – Verify password

Synopsis

mixed File_Passwd_Cvs::verifyPasswd ( string $user , string $pass )

Description

Verify the password of a certain user.

Parameter

string $user

user whose password should be verified

string $pass

the plaintext password that should be verified

Return value

Returns TRUE if passwords equal, FALSE if the don't or PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_EXISTS_NOT, if user doesn't exist.

Note

This function can not be called statically.

File_Passwd_Cvs::generatePassword

File_Passwd_Cvs::generatePassword() – Generate password

Synopsis

string File_Passwd_Cvs::generatePassword ( string $pass , string $salt = null )

Description

Generate a "CVS" pserver style password.

Parameter

string $pass

the plaintext password to encrypt

string $salt

the salt to use for encryption (usually empty)

Return value

Returns string encrypted password.

Example

File_Passwd_Cvs::generatePassword()

<?php
require_once 'File/Passwd/Cvs.php';
$pass = File_Passwd_Cvs::generatePassword('secret');
?>

Note

This function should be called statically.

File_Passwd_Smb

Manipulate SMB server passwd files. (inherited methods)

File_Passwd_Smb::staticAuth

File_Passwd_Smb::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Smb.php';

mixed File_Passwd_Smb::staticAuth ( string $file , string $user , string $pass , string $mode )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

string $mode

encryption mode ('nt'|'lm') NTHASH or LMHASH

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed /only if auth fails)
FILE_PASSWD_E_INVALID_ENC_MODE supplied encryption mode was invalid

Note

This function should be called statically.

File_Passwd_Smb::File_Passwd_Smb

File_Passwd_Smb::File_Passwd_Smb() – Constructor

Synopsis

require_once 'File/Passwd/Smb.php';

object &new File_Passwd_Smb ( string $file = 'smbpasswd' )

Description

Initialize a new File_Passwd_Smb object with the given path to passwd file.

Parameter

string $file

path to SMB passwd file

Return value

Returns object File_Passwd_Smb.

Note

This function can not be called statically.

File_Passwd_Smb::parse

File_Passwd_Smb::parse() – Parse file

Synopsis

mixed File_Passwd_Smb::parse ( )

Description

Parse the SMB passwd file. (package developer related)

This usually happens in File_Passwd_Smb::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_INVALID_FORMAT, if passwd file has invalid format.

Note

This function can not be called statically.

File_Passwd_Smb::save

File_Passwd_Smb::save() – Save changes

Synopsis

mixed File_Passwd_Smb::save ( )

Description

Apply changes and rewrite SMB passwd file.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Smb::addUser

File_Passwd_Smb::addUser() – Add an user

Synopsis

mixed File_Passwd_Smb::addUser ( string $user , string $pass , array $params , boolean $isMachine = false )

Description

Add an SMB user/machine account.

Parameter

string $user

the user/machine to add

string $pass

the new plaintext password

array $params

additional properties of account:

  • userid
  • flags
  • lct
  • comment
boolean $isMachine

whether to add an machine account

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_ALREADY account already exists
FILE_PASSWD_E_INVALID_CHARS user/machine name contains illegal characters

Note

This function can not be called statically.

File_Passwd_Smb::modUser

File_Passwd_Smb::modUser() – Modify a user

Synopsis

mixed File_Passwd_Smb::modUser ( string $user , array $params )

Description

Modify a certain user.

You shouldn't modify the password with this method, use File_Passwd_Smb::changePasswd() instead.

Parameter

string $user

the user to modify

array $params

an associative array of properties to change

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT account doesn't exist
FILE_PASSWD_E_INVALID_PROPERTY any supplied property was invalid

Note

This function can not be called statically.

File_Passwd_Smb::changePasswd

File_Passwd_Smb::changePasswd() – Change password

Synopsis

mixed File_Passwd_Smb::changePasswd ( string $user , string $pass )

Description

Change the passwd of a certain user.

Parameter

string $user

the user whose passwd should be changed

string $pass

the new plaintext passwd

Return value

Returns TRUE on success, PEAR_Error on failure.

Returns PEAR_Error FILE_PASSWD_E_EXISTS_NOT, if user doesn't exist.

Note

This function can not be called statically.

File_Passwd_Smb::verifyPasswd

File_Passwd_Smb::verifyPasswd() – Verify password

Synopsis

mixed File_Passwd_Smb::verifyPasswd ( string $user , string $pass )

Description

Verifies an account with the given plaintext password.

Parameter

string $user

username

string $pass

the plaintext password

Return value

Returns TRUE if passwds equal, FALSE if they don't or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_UNDEFINED if account is disabled

Note

This function can not be called statically.

File_Passwd_Smb::verifyEncryptedPasswd

File_Passwd_Smb::verifyEncryptedPasswd() – Verify encrypted password

Synopsis

mixed File_Passwd_Smb::verifyEncryptedPasswd ( string $user , string $nthash , string $lmhash = '' )

Description

Verify the encrypted password of an user/machine.

We prefer NT-Hash instead of weak LAN-Manager-Hash.

Parameter

string $user

username

string $nthash

NT-Hash in hex

string $lmhash

LAN-Manager-Hash in hex

Return value

Returns TRUE if passwds equal, FALSE if they don't or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_UNDEFINED if account is disabled

Note

This function can not be called statically.

File_Passwd_Smb::generatePassword

File_Passwd_Smb::generatePassword() – Generate password

Synopsis

string File_Passwd_Smb::generatePassword ( string $pass , string $mode = 'nt' )

Description

Generate a "Samba" server style password.

The encryption mode can either be FILE_PASSWD_NT or FILE_PASSWD_LM.

Parameter

string $pass

the plaintext password to encrypt

string $mode

the encryption mode to use

Return value

Returns string encrypted password.

Example

File_Passwd_Smb::generatePassword()

<?php
require_once 'File/Passwd/Smb.php';
$pass = File_Passwd_Smb::generatePassword('secret', FILE_PASSWD_LM);
?>

Note

This function should be called statically.

See

See also Crypt_CHAP_MSv1::ntPasswordHash() , Crypt_CHAP_MSv1::lmPasswordHash() .

File_Passwd_Authbasic

Manipulate AuthUserFiles. (inherited methods)

File_Passwd_Authbasic::staticAuth

File_Passwd_Authbasic::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Authbasic.php';

mixed File_Passwd_Authbasic::staticAuth ( string $file , string $user , string $pass , string $mode )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

string $mode

des, sha or md5

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed /only if auth fails)

Note

This function should be called statically.

File_Passwd_Authbasic::File_Passwd_Authbasic

File_Passwd_Authbasic::File_Passwd_Authbasic() – Constructor

Synopsis

require_once 'File/Passwd/Authbasic.php';

object &new File_Passwd_Authbasic ( string $file = '.htpasswd' )

Description

Initialise a new File_Passwd_Authbasic object with the given path to the passwd file.

Parameter

string $file

path to AuthUserFile

Return value

Returns object File_Passwd_Authbasic.

Note

This function can not be called statically.

File_Passwd_Authbasic::parse

File_Passwd_Authbasic::parse() – Parse the AuthUserFile

Synopsis

mixed File_Passwd_Authbasic::parse ( )

Description

Parse the AuthUserFile. (package developer related)

This usually happens in File_Passwd_Authbasic::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_INVALID_FORMAT passwd file has invalid format

Note

This function can not be called statically.

File_Passwd_Authbasic::save

File_Passwd_Authbasic::save() – Save changes

Synopsis

mixed File_Passwd_Authbasic::save ( )

Description

Apply changes and rewrite AuthUserFile.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Authbasic::addUser

File_Passwd_Authbasic::addUser() – Add an user

Synopsis

mixed File_Passwd_Authbasic::addUser ( string $user , string $pass )

Description

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

Parameter

string $user

username

string $pass

plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_ALREADY the user to add already exists
FILE_PASSWD_E_INVALID_CHARS the username to add contains illegal characters

Note

This function can not be called statically.

File_Passwd_Authbasic::changePasswd

File_Passwd_Authbasic::changePasswd() – Change password

Synopsis

mixed File_Passwd_Authbasic::changePasswd ( string $user , string $pass )

Description

Change the password of a certain user.

Parameter

string $user

the user whose password should be changed

string $pass

the new plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT the user to delete doesn't exist

Note

This function can not be called statically.

File_Passwd_Authbasic::verifyPasswd

File_Passwd_Authbasic::verifyPasswd() – Verify password

Synopsis

mixed File_Passwd_Authbasic::verifyPasswd ( string $user , string $pass )

Description

Verify the password of a certain user.

Parameter

string $user

the user whose password should be verified

string $pass

the plaintext password to verify

Return value

Returns TRUE if passwords equal, FALSE if they don't, or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT user doesn't exist
FILE_PASSWD_E_INVALID_ENC_MODE invalid encryption mode was supplied

Note

This function can not be called statically.

File_Passwd_Authbasic::getMode

File_Passwd_Authbasic::getMode() – Get actual encryption mode

Synopsis

string File_Passwd_Authbasic::getMode ( )

Description

Get the actual encryption mode.

Return value

string - actual encryption mode

Note

This function can not be called statically.

File_Passwd_Authbasic::setMode

File_Passwd_Authbasic::setMode() – Set the encryption mode

Synopsis

mixed File_Passwd_Authbasic::setMode ( string $mode )

Description

You can choose one of md5, sha or des.

ATTN: DES encryption not available on Win32!

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

Parameter

string $mode

the encryption mode to use

Return value

Returns TRUE on success, PEAR_Error on failure.

Note

This function can not be called statically.

File_Passwd_Authbasic::listModes

File_Passwd_Authbasic::listModes() – Get supported encryption modes

Synopsis

array File_Passwd_Authbasic::listModes ( )

Description

Returns an array of supported encryption modes.


<pre>
array
 + md5
 + sha
 + des
</pre>

ATTN: DES encryption not available on Win32!

Return value

array - supported encryption modes.

Note

This function can not be called statically.

File_Passwd_Authbasic::generatePassword

File_Passwd_Authbasic::generatePassword() – Generate password

Synopsis

mixed File_Passwd_Authbasic::generatePassword ( string $pass , string $mode = 'des' , string $salt = null )

Description

Generate a password usable for "AuthBasic" authentication.

The encryption mode can either be FILE_PASSWD_DES, FILE_PASSWD_SHA or FILE_PASSWD_MD5.

Parameter

string $pass

the plaintext password to encrypt

string $mode

the encryption mode to use

string $salt

the salt to use for encryption (usually empty)

Return value

Returns string encrypted password, or PEAR_Error FILE_PASSWD_E_INVALID_ENC_MODE if encryption mode is not supported.

Example

File_Passwd_Authbasic::generatePassword()

<?php
require_once 'File/Passwd/Authbasic.php';
$pass = File_Passwd_Authbasic::generatePassword('secret', FILE_PASSWD_MD5);
?>

Note

This function should be called statically.

File_Passwd_Authdigest

Manipulate AuthDigestFiles. (inherited methods)

File_Passwd_Authdigest::staticAuth

File_Passwd_Authdigest::staticAuth() – Fast authentication

Synopsis

require_once 'File/Passwd/Authdigest.php';

mixed File_Passwd_Authdigest::staticAuth ( string $file , string $user , string $pass , string $realm )

Description

Static user authentication.

Parameter

string $file

path to passwd file

string $user

user to authenticate

string $pass

plaintext password

string $realm

the realm the user should be in

Return value

Returns TRUE if authenticated, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_NOT_EXISTS passwd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed (only if auth fails)

Note

This function should be called statically.

File_Passwd_Authdigest::File_Passwd_Authdigest

File_Passwd_Authdigest::File_Passwd_Authdigest() – Constructor

Synopsis

require_once 'File/Passwd/Authdigest.php';

object &new File_Passwd_Authdigest ( string $file = '.htdigest' )

Description

Initialize a new object of File_Passwd_Authdigest with the specified path to the AuthDigestFile.

Parameter

string $file

path to AuthDigestFile

Return value

Returns object File_Passwd_Authdigest.

Note

This function can not be called statically.

File_Passwd_Authdigest::parse

File_Passwd_Authdigest::parse() – Parse the AuthDigestFile

Synopsis

mixed File_Passwd_Authdigest::parse ( )

Description

Parse the AuthDigestFile. (package developer related)

This usually happens in File_Passwd_Authdigest::load() .

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_INVALID_FORMAT AuthDigestFile has invalid format

Note

This function can not be called statically.

File_Passwd_Authdigest::save

File_Passwd_Authdigest::save() – Save changes

Synopsis

mixed File_Passwd_Authdigest::save ( )

Description

Apply changes and rewrite AuthDigestFile.

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_DIR_NOT_CREATED directory in which the passwd file should reside couldn't be created
FILE_PASSWD_E_FILE_NOT_OPENED passwd file couldn't be opened in write mode
FILE_PASSWD_E_FILE_NOT_LOCKED passwd file couldn't be locked exclusively
FILE_PASSWD_E_FILE_NOT_UNLOCKED passwd file couldn't be unlocked
FILE_PASSWD_E_FILE_NOT_CLOSED passwd file couldn't be closed

Note

This function can not be called statically.

File_Passwd_Authdigest::addUser

File_Passwd_Authdigest::addUser() – Add an user

Synopsis

mixed File_Passwd_Authdigest::addUser ( string $user , string $realm , string $pass )

Description

Add an user to the AuthDigestFile.

$user and $realm must start with an alphabetical charachter and must NOT contain any other characters than alphanumerics, the underline and dash.

Parameter

string $user

the user to add

string $realm

the realm the user should be in

string $pass

the plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_ALREADY user already exists in the supplied realm
FILE_PASSWD_E_INVLAID_CHARS user or realm contains illegal characters

Note

This function can not be called statically.

File_Passwd_Authdigest::changePasswd

File_Passwd_Authdigest::changePasswd() – Change password

Synopsis

mixed File_Passwd_Authdigest::changePasswd ( string $user , string $realm , string $pass )

Description

Change the password of a certain user in a specific realm.

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

Parameter

string $user

the user whose password should be changed

string $realm

the realm the user is in

string $pass

the new plaintext password

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_USER_NOT_IN_REALM user doesn't exist in the supplied realm
FILE_PASSWD_E_INVALID_CHARS user or realm contains illegal characters

Note

This function can not be called statically.

File_Passwd_Authdigest::verifyPasswd

File_Passwd_Authdigest::verifyPasswd() – Verifiy password

Synopsis

mixed File_Passwd_Authdigest::verifyPasswd ( string $user , string $realm , string $pass )

Description

Verify the password of an user in a certain realm.

Parameter

string $user

the user whose password should be verified

string $realm

the realm the user is in

string $pass

the plaintext password to verify

Return value

Retruns TRUE if passwords equal, FALSE if they don't, or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_USER_NOT_IN_REALM the specified user doesn't exist in the supplied realm

Note

This function can not be called statically.

File_Passwd_Authdigest::delUserInRealm

File_Passwd_Authdigest::delUserInRealm() – Delete a user

Synopsis

mixed File_Passwd_Authdigest::delUserInRealm ( string $user , string $inRealm )

Description

Delete a certain user in a specific realm.

Parameter

string $user

the user to remove

string $inRealm

the realm the user should be in

Return value

Returns TRUE on success, PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_USER_NOT_IN_REALM user doesn't exist in the supplied realm

Note

This function can not be called statically.

File_Passwd_Authdigest::listUserInRealm

File_Passwd_Authdigest::listUserInRealm() – List user

Synopsis

array File_Passwd_Authdigest::listUserInRealm ( string $inRealm = '' )

Description

List all user af either one specific or all realms.

Parameter

string $inRealm

the realm to list users of

Return value

Returns array:

Note

This function can not be called statically.

File_Passwd_Authdigest::userInRealm

File_Passwd_Authdigest::userInRealm() – Ckeck if a certain user is in a specific realm

Synopsis

require_once 'Passwd/Authdigest.php';

boolean File_Passwd_Authdigest::userInRealm ( string $user , string $realm )

Description

Ckeck if a certain user is in a specific realm.

Parameter

string $user

the user to check

string $realm

the realm the user shuold be in

Return value

Returns TRUE if user is in realm, FALSE if not or PEAR_Error on failure.

Possible PEAR_Error values
Error Code Summary
FILE_PASSWD_E_EXISTS_NOT specified realm doesn't exist

Note

This function can not be called statically.

File_Passwd_Authdigest::generatePassword

File_Passwd_Authdigest::generatePassword() – Generate password

Synopsis

string File_Passwd_Authdigest::generatePassword ( string $user , string $realm , string $pass )

Description

Generate a password usable for "AuthDigest" authentication.

Parameter

string $user

the username

string $realm

the realm the user is in

string $pass

the plaintext password

Return value

Returns string encrypted password.

Example

File_Passwd_Authdigest::generatePassword()

<?php
require_once 'File/Passwd/Authdigest.php';
$pass = File_Passwd_Authdigest::generatePassword('mike', 'restricted', 'secret');
?>

Note

This function should be called statically.