JavaScript Editor Javascript validator     Web page editor 


File_Passwd::staticAuth() -- Fast authentication


require_once 'File/Passwd.php';

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


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:


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.

Table 43-1. Possible PEAR_Error values

Error CodeSummary
FILE_PASSWD_E_NOT_EXISTSpasswd file doesn't exist
FILE_PASSWD_E_FILE_NOT_OPENEDpasswd file couldn't be opened in read mode
FILE_PASSWD_E_FILE_NOT_LOCKEDpasswd file couldn't be locked shared
FILE_PASSWD_E_FILE_NOT_UNLOCKEDpasswd file couldn't be unlocked (only if auth fails)
FILE_PASSWD_E_FILE_NOT_CLOSEDpasswd file couldn't be closed /only if auth fails)
FILE_PASSWD_E_UNDEFINEDif class/file couldn't be loaded
FILE_PASSWD_E_INVALID_ENC_MODEsupplied encryption mode is not supported
FILE_PASSWD_E_USER_NOT_IN_REALMuser doesn't exist in this realm (only File_Passwd_Authdigest)


This function should be called statically.

JavaScript Editor Javascript validator     Web page editor