cvs: pear /File_Passwd package.xml /File_Passwd/Passwd Authbasic.php Authdigest.php Common.php Cvs.php Smb.php Unix.php /File_Passwd/tests
test_cvs.php
| From: | Michael Wallner | Date: | Mon, 07 Jun 2004 19:19:48 +0000 |
| Subject: | cvs: pear /File_Passwd package.xml /File_Passwd/Passwd Authbasic.php Authdigest.php Common.php Cvs.php Smb.php Unix.php /File_Passwd/tests test_cvs.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-20327@lists.php.net to get a copy of this message | ||
mike Mon Jun 7 15:19:48 2004 EDT
Modified files:
/pear/File_Passwd/Passwd Authbasic.php Authdigest.php Common.php
Cvs.php Smb.php Unix.php
/pear/File_Passwd package.xml
/pear/File_Passwd/tests test_cvs.php
Log:
* added File_Passwd_*::generatePassword() (cox[at]php.net)
http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Authbasic.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Authbasic.php diff -u pear/File_Passwd/Passwd/Authbasic.php:1.14 pear/File_Passwd/Passwd/Authbasic.php:1.15 --- pear/File_Passwd/Passwd/Authbasic.php:1.14 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Authbasic.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Authbasic.php,v 1.14 2004/03/14 14:28:12 mike Exp $ +// $Id: Authbasic.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate AuthUserFiles as used for HTTP Basic Authentication. @@ -51,7 +51,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Authbasic extends File_Passwd_Common @@ -88,7 +88,7 @@ */ function File_Passwd_Authbasic($file = '.htpasswd') { - $this->__construct($file); + File_Passwd_Authbasic::__construct($file); } /** @@ -358,5 +358,30 @@ $this->_contents = array(); return true; } + + /** + * Generate Password + * + * Returns PEAR_Error FILE_PASSD_E_INVALID_ENC_MODE if the supplied + * encryption mode is not supported. + * + * @static + * @access public + * @return mixed The crypted password on success or PEAR_Error on failure. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use (des|md5|sha). + * @param string $salt The salt to use. + */ + function generatePassword($pass, $mode = FILE_PASSWD_DES, $salt = null) + { + if (!in_array(strToLower($mode), array('des', 'md5', 'sha'))) { + return PEAR::raiseError( + sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $mode), + FILE_PASSWD_E_INVALID_ENC_MODE + ); + } + return File_Passwd_Authbasic::_genPass($pass, $salt, $mode); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Authdigest.php?r1=1.9&r2=1.10&ty=u Index: pear/File_Passwd/Passwd/Authdigest.php diff -u pear/File_Passwd/Passwd/Authdigest.php:1.9 pear/File_Passwd/Passwd/Authdigest.php:1.10 --- pear/File_Passwd/Passwd/Authdigest.php:1.9 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Authdigest.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Authdigest.php,v 1.9 2004/03/14 14:28:12 mike Exp $ +// $Id: Authdigest.php,v 1.10 2004/06/07 19:19:47 mike Exp $ /** * Manipulate AuthDigestFiles as used for HTTP Digest Authentication. @@ -53,7 +53,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.9 $ +* @version $Revision: 1.10 $ * @access public */ class File_Passwd_Authdigest extends File_Passwd_Common @@ -74,7 +74,7 @@ */ function File_Passwd_Authdigest($file = '.htdigest') { - $this->__construct($file); + parent::__construct($file); } /** @@ -333,5 +333,21 @@ $this->_contents = array(); return true; } + + /** + * Generate Password + * + * @static + * @access public + * @return string The crypted password. + * @param string $user The username. + * @param string $realm The realm the user is in. + * @param string $pass The plaintext password. + */ + function generatePassword($user, $realm, $pass) + { + return md5("$user:$realm:$pass"); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Common.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Passwd/Passwd/Common.php diff -u pear/File_Passwd/Passwd/Common.php:1.11 pear/File_Passwd/Passwd/Common.php:1.12 --- pear/File_Passwd/Passwd/Common.php:1.11 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Common.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.11 2004/03/14 14:28:12 mike Exp $ +// $Id: Common.php,v 1.12 2004/06/07 19:19:47 mike Exp $ /** * Baseclass for File_Passwd_* classes. @@ -44,7 +44,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.11 $ +* @version $Revision: 1.12 $ * @access protected * @internal extend this class for your File_Passwd_* class */ @@ -219,7 +219,7 @@ return $fh; } $this->_contents = array(); - while ($line = fgets($fh)){ + while ($line = fgets($fh)) { $line = trim(preg_replace('/^(\S*.*)#.*$/', '\\1', $line)); if (empty($line)) { continue; @@ -364,7 +364,7 @@ if (PEAR::isError($fh)) { return $fh; } - while($line = fgets($fh)){ + while ($line = fgets($fh)) { if (strstr($line, $id)) { File_Passwd_Common::_close($fh); return trim($line); http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Cvs.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Passwd/Passwd/Cvs.php diff -u pear/File_Passwd/Passwd/Cvs.php:1.11 pear/File_Passwd/Passwd/Cvs.php:1.12 --- pear/File_Passwd/Passwd/Cvs.php:1.11 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Cvs.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Cvs.php,v 1.11 2004/03/14 14:28:12 mike Exp $ +// $Id: Cvs.php,v 1.12 2004/06/07 19:19:47 mike Exp $ /** * Manipulate CVS pserver passwd files. @@ -54,7 +54,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.11 $ +* @version $Revision: 1.12 $ * @access public */ class File_Passwd_Cvs extends File_Passwd_Common @@ -66,7 +66,7 @@ */ function File_Passwd_Cvs($file = 'passwd') { - $this->__construct($file); + parent::__construct($file); } /** @@ -93,7 +93,7 @@ return $line; } @list(,$real) = explode(':', $line); - return (File_Passwd_Cvs::_genPass($pass, $real) === $real); + return (File_Passwd_Cvs::generatePassword($pass, $real) === $real); } /** @@ -195,7 +195,7 @@ FILE_PASSWD_E_INVALID_CHARS ); } - $this->_users[$user]['passwd'] = $this->_genPass($pass); + $this->_users[$user]['passwd'] = $this->generatePassword($pass); $this->_users[$user]['system'] = $system_user; return true; } @@ -220,7 +220,7 @@ ); } $real = $this->_users[$user]['passwd']; - return ($real === $this->_genPass($pass, $real)); + return ($real === $this->generatePassword($pass, $real)); } /** @@ -240,7 +240,7 @@ FILE_PASSWD_E_EXISTS_NOT ); } - $this->_users[$user]['passwd'] = $this->_genPass($pass); + $this->_users[$user]['passwd'] = $this->generatePassword($pass); return true; } @@ -280,13 +280,13 @@ /** * Generate crypted password * - * @throws PEAR_Error + * @static * @access public * @return string the crypted password * @param string $pass new plaintext password * @param string $salt new crypted password from which to gain the salt */ - function _genPass($pass, $salt = null) + function generatePassword($pass, $salt = null) { return File_Passwd::crypt_des($pass, $salt); } http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Smb.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Smb.php diff -u pear/File_Passwd/Passwd/Smb.php:1.14 pear/File_Passwd/Passwd/Smb.php:1.15 --- pear/File_Passwd/Passwd/Smb.php:1.14 Tue Mar 30 05:41:30 2004 +++ pear/File_Passwd/Passwd/Smb.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Smb.php,v 1.14 2004/03/30 10:41:30 mike Exp $ +// $Id: Smb.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate SMB server passwd files. @@ -72,7 +72,7 @@ * @author Michael Bretterklieber <michael@bretterklieber.com> * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Smb extends File_Passwd_Common @@ -93,7 +93,7 @@ */ function File_Passwd_Smb($file = 'smbpasswd') { - $this->__construct($file); + File_Passwd_Smb::__construct($file); } /** @@ -393,6 +393,25 @@ $userdata['comment']. "\n"; } return $this->_save($content); - } + } + + /** + * Generate Password + * + * @static + * @access public + * @return string The crypted password. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use (nt|lm). + */ + function generatePassword($pass, $mode = 'nt') + { + $chap = &new Crypt_CHAP_MSv1; + $hash = strToLower($mode) == 'nt' ? + $chap->ntPasswordHash($pass) : + $chap->lmPasswordHash($pass); + return strToUpper(bin2hex($hash)); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Unix.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Unix.php diff -u pear/File_Passwd/Passwd/Unix.php:1.14 pear/File_Passwd/Passwd/Unix.php:1.15 --- pear/File_Passwd/Passwd/Unix.php:1.14 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Unix.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Unix.php,v 1.14 2004/03/14 14:28:12 mike Exp $ +// $Id: Unix.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate standard Unix passwd files. @@ -61,7 +61,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Unix extends File_Passwd_Common @@ -114,7 +114,7 @@ */ function File_Passwd_Unix($file = 'passwd') { - $this->__construct($file); + parent::__construct($file); } /** @@ -608,7 +608,7 @@ $crypters = get_class_methods('File_Passwd'); } - $mode = is_null($mode) ? strToLower($this->_mode) : strToLower($mode); + $mode = !isset($mode) ? strToLower($this->_mode) : strToLower($mode); $func = 'crypt_' . $mode; if (!in_array($func, $crypters)) { @@ -620,5 +620,31 @@ return call_user_func(array('File_Passwd', $func), $pass, $salt); } + + /** + * Generate Password + * + * Returns PEAR_Error FILE_PASSD_E_INVALID_ENC_MODE if the supplied + * encryption mode is not supported. + * + * @see File_Passwd + * @static + * @access public + * @return mixed The crypted password on success or PEAR_Error on failure. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use. + * @param string $salt The salt to use. + */ + function generatePassword($pass, $mode = 'md5', $salt = null) + { + if (!isset($mode)) { + return PEAR::raiseError( + sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, '<NULL>'), + FILE_PASSWD_E_INVALID_ENC_MODE + ); + } + return File_Passwd_Unix::_genPass($pass, $salt, $mode); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/package.xml?r1=1.32&r2=1.33&ty=u Index: pear/File_Passwd/package.xml diff -u pear/File_Passwd/package.xml:1.32 pear/File_Passwd/package.xml:1.33 --- pear/File_Passwd/package.xml:1.32 Tue Mar 30 05:41:31 2004 +++ pear/File_Passwd/package.xml Mon Jun 7 15:19:47 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.32 $ --> +<!-- $Revision: 1.33 $ --> <package version="1.0"> <name>File_Passwd</name> <license>PHP</license> @@ -16,11 +16,11 @@ </maintainer> </maintainers> <release> - <version>1.0.2</version> - <date>2004-03-30</date> + <version>1.1.0</version> + <date>2004-06-07</date> <state>stable</state> <notes> -* Maintainance release for Crypt_CHAP-1.0.0 ++ Added public static generatePassword() methods to all File_Passwd subclasses except File_Passwd_Custom. </notes> <filelist> <dir name="/" baseinstalldir="File"> http://cvs.php.net/diff.php/pear/File_Passwd/tests/test_cvs.php?r1=1.2&r2=1.3&ty=u Index: pear/File_Passwd/tests/test_cvs.php diff -u pear/File_Passwd/tests/test_cvs.php:1.2 pear/File_Passwd/tests/test_cvs.php:1.3 --- pear/File_Passwd/tests/test_cvs.php:1.2 Thu Sep 25 10:21:36 2003 +++ pear/File_Passwd/tests/test_cvs.php Mon Jun 7 15:19:47 2004 @@ -115,11 +115,11 @@ } /** - * Regression test for File_Passwd_Cvs._genPass method + * Regression test for File_Passwd_Cvs.generatePassword method * @access public */ - function test_genPass(){ - $this->assertEquals('12IbR.gJ8wcpc', $this->pwd->_genPass(123, '12IbR.gJ8wcpc')); + function testgeneratePassword(){ + $this->assertEquals('12IbR.gJ8wcpc', $this->pwd->generatePassword(123, '12IbR.gJ8wcpc')); } function teststaticAuth(){
http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Authbasic.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Authbasic.php diff -u pear/File_Passwd/Passwd/Authbasic.php:1.14 pear/File_Passwd/Passwd/Authbasic.php:1.15 --- pear/File_Passwd/Passwd/Authbasic.php:1.14 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Authbasic.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Authbasic.php,v 1.14 2004/03/14 14:28:12 mike Exp $ +// $Id: Authbasic.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate AuthUserFiles as used for HTTP Basic Authentication. @@ -51,7 +51,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Authbasic extends File_Passwd_Common @@ -88,7 +88,7 @@ */ function File_Passwd_Authbasic($file = '.htpasswd') { - $this->__construct($file); + File_Passwd_Authbasic::__construct($file); } /** @@ -358,5 +358,30 @@ $this->_contents = array(); return true; } + + /** + * Generate Password + * + * Returns PEAR_Error FILE_PASSD_E_INVALID_ENC_MODE if the supplied + * encryption mode is not supported. + * + * @static + * @access public + * @return mixed The crypted password on success or PEAR_Error on failure. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use (des|md5|sha). + * @param string $salt The salt to use. + */ + function generatePassword($pass, $mode = FILE_PASSWD_DES, $salt = null) + { + if (!in_array(strToLower($mode), array('des', 'md5', 'sha'))) { + return PEAR::raiseError( + sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $mode), + FILE_PASSWD_E_INVALID_ENC_MODE + ); + } + return File_Passwd_Authbasic::_genPass($pass, $salt, $mode); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Authdigest.php?r1=1.9&r2=1.10&ty=u Index: pear/File_Passwd/Passwd/Authdigest.php diff -u pear/File_Passwd/Passwd/Authdigest.php:1.9 pear/File_Passwd/Passwd/Authdigest.php:1.10 --- pear/File_Passwd/Passwd/Authdigest.php:1.9 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Authdigest.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Authdigest.php,v 1.9 2004/03/14 14:28:12 mike Exp $ +// $Id: Authdigest.php,v 1.10 2004/06/07 19:19:47 mike Exp $ /** * Manipulate AuthDigestFiles as used for HTTP Digest Authentication. @@ -53,7 +53,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.9 $ +* @version $Revision: 1.10 $ * @access public */ class File_Passwd_Authdigest extends File_Passwd_Common @@ -74,7 +74,7 @@ */ function File_Passwd_Authdigest($file = '.htdigest') { - $this->__construct($file); + parent::__construct($file); } /** @@ -333,5 +333,21 @@ $this->_contents = array(); return true; } + + /** + * Generate Password + * + * @static + * @access public + * @return string The crypted password. + * @param string $user The username. + * @param string $realm The realm the user is in. + * @param string $pass The plaintext password. + */ + function generatePassword($user, $realm, $pass) + { + return md5("$user:$realm:$pass"); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Common.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Passwd/Passwd/Common.php diff -u pear/File_Passwd/Passwd/Common.php:1.11 pear/File_Passwd/Passwd/Common.php:1.12 --- pear/File_Passwd/Passwd/Common.php:1.11 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Common.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.11 2004/03/14 14:28:12 mike Exp $ +// $Id: Common.php,v 1.12 2004/06/07 19:19:47 mike Exp $ /** * Baseclass for File_Passwd_* classes. @@ -44,7 +44,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.11 $ +* @version $Revision: 1.12 $ * @access protected * @internal extend this class for your File_Passwd_* class */ @@ -219,7 +219,7 @@ return $fh; } $this->_contents = array(); - while ($line = fgets($fh)){ + while ($line = fgets($fh)) { $line = trim(preg_replace('/^(\S*.*)#.*$/', '\\1', $line)); if (empty($line)) { continue; @@ -364,7 +364,7 @@ if (PEAR::isError($fh)) { return $fh; } - while($line = fgets($fh)){ + while ($line = fgets($fh)) { if (strstr($line, $id)) { File_Passwd_Common::_close($fh); return trim($line); http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Cvs.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Passwd/Passwd/Cvs.php diff -u pear/File_Passwd/Passwd/Cvs.php:1.11 pear/File_Passwd/Passwd/Cvs.php:1.12 --- pear/File_Passwd/Passwd/Cvs.php:1.11 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Cvs.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Cvs.php,v 1.11 2004/03/14 14:28:12 mike Exp $ +// $Id: Cvs.php,v 1.12 2004/06/07 19:19:47 mike Exp $ /** * Manipulate CVS pserver passwd files. @@ -54,7 +54,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.11 $ +* @version $Revision: 1.12 $ * @access public */ class File_Passwd_Cvs extends File_Passwd_Common @@ -66,7 +66,7 @@ */ function File_Passwd_Cvs($file = 'passwd') { - $this->__construct($file); + parent::__construct($file); } /** @@ -93,7 +93,7 @@ return $line; } @list(,$real) = explode(':', $line); - return (File_Passwd_Cvs::_genPass($pass, $real) === $real); + return (File_Passwd_Cvs::generatePassword($pass, $real) === $real); } /** @@ -195,7 +195,7 @@ FILE_PASSWD_E_INVALID_CHARS ); } - $this->_users[$user]['passwd'] = $this->_genPass($pass); + $this->_users[$user]['passwd'] = $this->generatePassword($pass); $this->_users[$user]['system'] = $system_user; return true; } @@ -220,7 +220,7 @@ ); } $real = $this->_users[$user]['passwd']; - return ($real === $this->_genPass($pass, $real)); + return ($real === $this->generatePassword($pass, $real)); } /** @@ -240,7 +240,7 @@ FILE_PASSWD_E_EXISTS_NOT ); } - $this->_users[$user]['passwd'] = $this->_genPass($pass); + $this->_users[$user]['passwd'] = $this->generatePassword($pass); return true; } @@ -280,13 +280,13 @@ /** * Generate crypted password * - * @throws PEAR_Error + * @static * @access public * @return string the crypted password * @param string $pass new plaintext password * @param string $salt new crypted password from which to gain the salt */ - function _genPass($pass, $salt = null) + function generatePassword($pass, $salt = null) { return File_Passwd::crypt_des($pass, $salt); } http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Smb.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Smb.php diff -u pear/File_Passwd/Passwd/Smb.php:1.14 pear/File_Passwd/Passwd/Smb.php:1.15 --- pear/File_Passwd/Passwd/Smb.php:1.14 Tue Mar 30 05:41:30 2004 +++ pear/File_Passwd/Passwd/Smb.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Smb.php,v 1.14 2004/03/30 10:41:30 mike Exp $ +// $Id: Smb.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate SMB server passwd files. @@ -72,7 +72,7 @@ * @author Michael Bretterklieber <michael@bretterklieber.com> * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Smb extends File_Passwd_Common @@ -93,7 +93,7 @@ */ function File_Passwd_Smb($file = 'smbpasswd') { - $this->__construct($file); + File_Passwd_Smb::__construct($file); } /** @@ -393,6 +393,25 @@ $userdata['comment']. "\n"; } return $this->_save($content); - } + } + + /** + * Generate Password + * + * @static + * @access public + * @return string The crypted password. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use (nt|lm). + */ + function generatePassword($pass, $mode = 'nt') + { + $chap = &new Crypt_CHAP_MSv1; + $hash = strToLower($mode) == 'nt' ? + $chap->ntPasswordHash($pass) : + $chap->lmPasswordHash($pass); + return strToUpper(bin2hex($hash)); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/Passwd/Unix.php?r1=1.14&r2=1.15&ty=u Index: pear/File_Passwd/Passwd/Unix.php diff -u pear/File_Passwd/Passwd/Unix.php:1.14 pear/File_Passwd/Passwd/Unix.php:1.15 --- pear/File_Passwd/Passwd/Unix.php:1.14 Sun Mar 14 09:28:12 2004 +++ pear/File_Passwd/Passwd/Unix.php Mon Jun 7 15:19:47 2004 @@ -11,7 +11,7 @@ // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: Unix.php,v 1.14 2004/03/14 14:28:12 mike Exp $ +// $Id: Unix.php,v 1.15 2004/06/07 19:19:47 mike Exp $ /** * Manipulate standard Unix passwd files. @@ -61,7 +61,7 @@ * * @author Michael Wallner <mike@php.net> * @package File_Passwd -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * @access public */ class File_Passwd_Unix extends File_Passwd_Common @@ -114,7 +114,7 @@ */ function File_Passwd_Unix($file = 'passwd') { - $this->__construct($file); + parent::__construct($file); } /** @@ -608,7 +608,7 @@ $crypters = get_class_methods('File_Passwd'); } - $mode = is_null($mode) ? strToLower($this->_mode) : strToLower($mode); + $mode = !isset($mode) ? strToLower($this->_mode) : strToLower($mode); $func = 'crypt_' . $mode; if (!in_array($func, $crypters)) { @@ -620,5 +620,31 @@ return call_user_func(array('File_Passwd', $func), $pass, $salt); } + + /** + * Generate Password + * + * Returns PEAR_Error FILE_PASSD_E_INVALID_ENC_MODE if the supplied + * encryption mode is not supported. + * + * @see File_Passwd + * @static + * @access public + * @return mixed The crypted password on success or PEAR_Error on failure. + * @param string $pass The plaintext password. + * @param string $mode The encryption mode to use. + * @param string $salt The salt to use. + */ + function generatePassword($pass, $mode = 'md5', $salt = null) + { + if (!isset($mode)) { + return PEAR::raiseError( + sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, '<NULL>'), + FILE_PASSWD_E_INVALID_ENC_MODE + ); + } + return File_Passwd_Unix::_genPass($pass, $salt, $mode); + } + } ?> http://cvs.php.net/diff.php/pear/File_Passwd/package.xml?r1=1.32&r2=1.33&ty=u Index: pear/File_Passwd/package.xml diff -u pear/File_Passwd/package.xml:1.32 pear/File_Passwd/package.xml:1.33 --- pear/File_Passwd/package.xml:1.32 Tue Mar 30 05:41:31 2004 +++ pear/File_Passwd/package.xml Mon Jun 7 15:19:47 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.32 $ --> +<!-- $Revision: 1.33 $ --> <package version="1.0"> <name>File_Passwd</name> <license>PHP</license> @@ -16,11 +16,11 @@ </maintainer> </maintainers> <release> - <version>1.0.2</version> - <date>2004-03-30</date> + <version>1.1.0</version> + <date>2004-06-07</date> <state>stable</state> <notes> -* Maintainance release for Crypt_CHAP-1.0.0 ++ Added public static generatePassword() methods to all File_Passwd subclasses except File_Passwd_Custom. </notes> <filelist> <dir name="/" baseinstalldir="File"> http://cvs.php.net/diff.php/pear/File_Passwd/tests/test_cvs.php?r1=1.2&r2=1.3&ty=u Index: pear/File_Passwd/tests/test_cvs.php diff -u pear/File_Passwd/tests/test_cvs.php:1.2 pear/File_Passwd/tests/test_cvs.php:1.3 --- pear/File_Passwd/tests/test_cvs.php:1.2 Thu Sep 25 10:21:36 2003 +++ pear/File_Passwd/tests/test_cvs.php Mon Jun 7 15:19:47 2004 @@ -115,11 +115,11 @@ } /** - * Regression test for File_Passwd_Cvs._genPass method + * Regression test for File_Passwd_Cvs.generatePassword method * @access public */ - function test_genPass(){ - $this->assertEquals('12IbR.gJ8wcpc', $this->pwd->_genPass(123, '12IbR.gJ8wcpc')); + function testgeneratePassword(){ + $this->assertEquals('12IbR.gJ8wcpc', $this->pwd->generatePassword(123, '12IbR.gJ8wcpc')); } function teststaticAuth(){