File_Passwd
[ class tree: File_Passwd ] [ index: File_Passwd ] [ all elements ]

Class: File_Passwd_Custom

Source Location: /File_Passwd-1.1.7/Passwd/Custom.php

Class Overview

File_Passwd_Common
   |
   --File_Passwd_Custom

Manipulate custom formatted passwd files


Author(s):

Version:

  • $Revision: 1.10 $

Methods


Inherited Variables

Inherited Methods

Class: File_Passwd_Common

File_Passwd_Common::__construct()
Constructor (ZE2)
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

Class Details

[line 46]
Manipulate custom formatted passwd files

Usage Example:

  1.  $cust &File_Passwd::factory('Custom');
  2.  $cust->setDelim('|');
  3.  $cust->load();
  4.  $cust->setEncFunc(array('File_Passwd''crypt_apr_md5'));
  5.  $cust->addUser('mike''pass');
  6.  $cust->save();

  • Author: Michael Wallner <mike@php.net>
  • Version: $Revision: 1.10 $
  • Access: public


[ Top ]


Method Detail

File_Passwd_Custom (Constructor)   [line 86]

object File_Passwd_Custom( [ $file = 'passwd'])

Constructor
  • Access: protected

Parameters:

   $file     

[ Top ]

addUser   [line 390]

mixed addUser( string $user, string $pass, [array $extra = array()])

Add an user

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'!

Returns a PEAR_Error if:

  • user already exists
  • user contains illegal characters
  • encryption mode is not supported
  • any element of the $extra array contains the delimiter char

  • Return: Returns &true; on success or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_EXISTS_ALREADY | FILE_PASSWD_E_INVALID_ENC_MODE | FILE_PASSWD_E_INVALID_CHARS
  • Access: public

Parameters:

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

[ Top ]

changePasswd   [line 501]

mixed changePasswd( string $user, string $pass)

Change the password of a certain user

Returns a PEAR_Error if:

  • user doesn't exists
  • encryption mode is not supported

  • Return: Returns &true; on success or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_EXISTS_NOT | FILE_PASSWD_E_INVALID_ENC_MODE
  • Access: public

Parameters:

string   $user     the user whose password should be changed
string   $pass     the new plaintext password

[ Top ]

getDelim   [line 169]

string getDelim( )

Get custom delimiter
  • Access: public

[ Top ]

getEncFunc   [line 215]

string getEncFunc( )

Get current custom encryption method

Possible return values (examples):

  • 'md5'
  • 'File_Passwd::crypt_md5'

  • Access: public

[ Top ]

getMap   [line 280]

array getMap( )

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

[ Top ]

modUser   [line 460]

mixed modUser( string $user, [array $properties = array()])

Modify properties of a certain user

  • DON'T MODIFY THE PASSWORD WITH THIS METHOD!
You should use this method only if the 'name map' is used, too.

Returns a PEAR_Error if:

  • user doesn't exist
  • any property contains the custom delimiter character


Parameters:

string   $user     the user to modify
array   $properties     an associative array of properties to modify

[ Top ]

parse   [line 328]

mixed parse( )

Parse the Custom password file

Returns a PEAR_Error if passwd file has invalid format.

  • Return: Returns &true; on success or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_INVALID_FORMAT
  • Access: public

Overrides File_Passwd_Common::parse() (Parse the content of the file)
[ Top ]

save   [line 303]

mixed save( )

Apply changes an rewrite passwd file

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: Returns &true; on success or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_FILE_NOT_OPENED | FILE_PASSWD_E_FILE_NOT_LOCKED | FILE_PASSWD_E_FILE_NOT_UNLOCKED | FILE_PASSWD_E_FILE_NOT_CLOSED
  • Access: public

Overrides File_Passwd_Common::save() (Apply changes and rewrite passwd file)
[ Top ]

setDelim   [line 153]

void setDelim( [string $delim = ':'])

Set delimiter

You can set a custom char to delimit the columns of a data set. Defaults to a colon (':'). Be aware that this char mustn't be in the values of your data sets.

  • Access: public

Parameters:

string   $delim     custom delimiting character

[ Top ]

setEncFunc   [line 189]

mixed setEncFunc( [mixed $function = array('File_Passwd', 'crypt_md5')])

Set encryption function

You can set a custom encryption function to use. The supplied function will be called by php's call_user_function(), so you can supply an array with a method of a class/object, too (i.e. array('File_Passwd', 'crypt_apr_md5').

  • Return: Returns &true; on success or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_INVALID_ENC_MODE
  • Access: public

Parameters:

mixed   $function     callable encryption function

[ Top ]

setMap   [line 259]

mixed setMap( [ $map = array()])

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.

Returns a PEAR_Error if $map was not of type array.


Parameters:

   $map     

[ Top ]

staticAuth   [line 119]

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

Fast authentication of a certain user

Returns a PEAR_Error if:

  • file doesn't exist
  • file couldn't be opened in read mode
  • file couldn't be locked exclusively
  • file couldn't be unlocked (only if auth fails)
  • file couldn't be closed (only if auth fails)
or no delimiter character $opts[1] was provided

  • Return: Returns &true; if authenticated, &false; if not or <classname>PEAR_Error</classname> on failure.
  • Throws: PEAR_Error FILE_PASSWD_E_UNDEFINED | FILE_PASSWD_E_FILE_NOT_OPENED | FILE_PASSWD_E_FILE_NOT_LOCKED | FILE_PASSWD_E_FILE_NOT_UNLOCKED | FILE_PASSWD_E_FILE_NOT_CLOSED | FILE_PASSWD_E_INVALID_ENC_MODE
  • Access: public

Parameters:

string   $file     path to passwd file
string   $user     user to authenticate
string   $pass     plaintext password
array   $otps     encryption function and delimiter charachter (in this order)
   $opts     

[ Top ]

useMap   [line 236]

boolean useMap( [boolean $bool = null])

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

Parameters:

boolean   $bool     whether to use the 'name map' or not

[ Top ]

verifyPasswd   [line 539]

mixed verifyPasswd( string $user, string $pass)

Verify the password of a certain user

Returns a PEAR_Error if:

  • user doesn't exist
  • encryption mode is not supported

  • Return: Returns &true; if passwors equal, &false; if they don't or <classname>PEAR_Error</classname> on fialure.
  • Throws: PEAR_Error FILE_PASSWD_E_EXISTS_NOT | FILE_PASSWD_E_INVALID_ENC_MODE
  • Access: public

Parameters:

string   $user     the user whose password should be verified
string   $pass     the password to verify

[ Top ]


Documentation generated on Sun, 04 Jan 2009 13:00:08 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.