RE: [PEAR-DEV] [patch] Auth: patch allowing usage of 'custom' form fieldnames for username & password
| From: | Herman Sinte Maartensdijk | Date: | Thu, 11 Mar 2004 08:39:20 +0000 |
| Subject: | RE: [PEAR-DEV] [patch] Auth: patch allowing usage of 'custom' form fieldnames for username & password | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-26287@lists.php.net to get a copy of this message | ||
Hmm it did not get through? I use Outlook (not express) but I guess that has
the same bug. I see the it is in CVS. I wonder how I missed it. I must have been fiddling with
too many different versions of Auth.php. I accidentally based my patch on the latest official
release of the Auth.php file. Oh well as long as a patch is in.
Looking at the patch from Michael Wallner I notice he sets the postUsername and postPassword
from the $options array. This ain't very friendly for wrapper classes that set different
default
values, which is why I implemented it with setters. Getters might be nice to for completeness
although I dont see any direct use for them.
I've re-attached my diff file to this mail with a .txt extension in case it did not arrive at
Yavor e.a.
Cheers,
Herman
-----Original Message-----
From: Cipriano Groenendal [mailto:cipri@cipri.com]
Sent: Wednesday, March 10, 2004 21:59
To: Herman Sinte Maartensdijk; pear-dev@lists.php.net
Subject: Re: [PEAR-DEV] [patch] Auth: patch allowing usage of 'custom'
form fieldnames for username & password
> I created a patch for the Auth package to support 'custom'
> form fieldnames for username & password instead of the
> fixed 'username' and 'password'
> Added 2 functions (setUsernameField and setPasswordField)
> to set the custom values if desired.
Hello :)
First of all, your patch didn't come through. Judging form your HTML mail,
you're using Outlook Express, which has a n asty little bug which means you
need to rename your patch file to .txt or it won't be accepted by the
mailing list.
Second, the change you have in your patch was recently added to the CVS
already after a patch from Michael Wallner mike@php.net, see the CVS[1] for
details of the file. This patch set those two options using the $options
array via the constructor, IIRC. However it might indeed also be a nice idea
to have setters/getters for these two fields. Thanks for your ideas and
wishing to contribute to PEAR however! I'm sure Yavor/The other Devs will
take a look at your patch and perhaps integrate the things it does better
then Mike's patch into the package :)
--
Cipriano
[1] http://cvs.php.net/diff.php/pear/Auth/Auth.php?r1=1.72&r2=1.73&ty=h
--- Auth.php.org Sun Nov 16 16:57:08 2003 +++ Auth.php Wed Mar 10 15:13:24 2004 @@ -17,6 +17,7 @@ // +----------------------------------------------------------------------+ // // $Id: Auth.php,v 1.67 2003/10/20 06:36:34 yavo Exp $ +// patched to enable username & password to be changable // require_once 'PEAR.php'; @@ -144,6 +145,22 @@ var $logoutCallback = ''; /** + * Auth username field + * Name of the formfield containing the username + * + * @var string + */ + var $_usernameField = 'username'; + + /** + * Auth password field + * Name of the formfield containing the password + * + * @var string + */ + var $_passwordField = 'password'; + + /** * Auth session-array name * * @var string @@ -240,12 +257,12 @@ { $post = &$this->_importGlobalVariable('post'); - if (isset($post['username']) && $post['username'] != '') { - $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post['username']) : $post['username']); + if (isset($post[$this->_usernameField]) && $post[$this->_usernameField] != '') { + $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_usernameField]) : $post[$this->_usernameField]); } - if (isset($post['password']) && $post['password'] != '') { - $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post['password']) : $post['password'] ); + if (isset($post[$this->_passwordField]) && $post[$this->_passwordField] != '') { + $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_passwordField]) : $post[$this->_passwordField] ); } } @@ -378,6 +395,36 @@ } // }}} + // {{{ setUsernameField() + + /** + * Set name of the formfield containing the username. + * + * @access public + * @param string New name for the username formfield + * @return void + */ + function setUsernameField($field = 'username') + { + $this->_usernameField = $field; + } + + // }}} + // {{{ setPasswordField() + + /** + * Set name of the formfield containing the passwordname. + * + * @access public + * @param string New name for the password formfield + * @return void + */ + function setPasswordField($field = 'password') + { + $this->_passwordField = $field; + } + + // }}} // {{{ setShowLogin() /** @@ -639,11 +686,11 @@ echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td>Username:</td>'."\n"; - echo ' <td><input type="text" name="username" value="' . $username . '" /></td>'."\n"; + echo ' <td><input type="text" name="' . $this->_usernameField . '" value="' . $username . '" /></td>'."\n"; echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td>Password:</td>'."\n"; - echo ' <td><input type="password" name="password" /></td>'."\n"; + echo ' <td><input type="password" name="' . $this->_passwordField . '" /></td>'."\n"; echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td colspan="2" bgcolor="#eeeeee"><input type="submit" /></td>'."\n";
--- Auth.php.org Sun Nov 16 16:57:08 2003 +++ Auth.php Wed Mar 10 15:13:24 2004 @@ -17,6 +17,7 @@ // +----------------------------------------------------------------------+ // // $Id: Auth.php,v 1.67 2003/10/20 06:36:34 yavo Exp $ +// patched to enable username & password to be changable // require_once 'PEAR.php'; @@ -144,6 +145,22 @@ var $logoutCallback = ''; /** + * Auth username field + * Name of the formfield containing the username + * + * @var string + */ + var $_usernameField = 'username'; + + /** + * Auth password field + * Name of the formfield containing the password + * + * @var string + */ + var $_passwordField = 'password'; + + /** * Auth session-array name * * @var string @@ -240,12 +257,12 @@ { $post = &$this->_importGlobalVariable('post'); - if (isset($post['username']) && $post['username'] != '') { - $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post['username']) : $post['username']); + if (isset($post[$this->_usernameField]) && $post[$this->_usernameField] != '') { + $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_usernameField]) : $post[$this->_usernameField]); } - if (isset($post['password']) && $post['password'] != '') { - $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post['password']) : $post['password'] ); + if (isset($post[$this->_passwordField]) && $post[$this->_passwordField] != '') { + $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_passwordField]) : $post[$this->_passwordField] ); } } @@ -378,6 +395,36 @@ } // }}} + // {{{ setUsernameField() + + /** + * Set name of the formfield containing the username. + * + * @access public + * @param string New name for the username formfield + * @return void + */ + function setUsernameField($field = 'username') + { + $this->_usernameField = $field; + } + + // }}} + // {{{ setPasswordField() + + /** + * Set name of the formfield containing the passwordname. + * + * @access public + * @param string New name for the password formfield + * @return void + */ + function setPasswordField($field = 'password') + { + $this->_passwordField = $field; + } + + // }}} // {{{ setShowLogin() /** @@ -639,11 +686,11 @@ echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td>Username:</td>'."\n"; - echo ' <td><input type="text" name="username" value="' . $username . '" /></td>'."\n"; + echo ' <td><input type="text" name="' . $this->_usernameField . '" value="' . $username . '" /></td>'."\n"; echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td>Password:</td>'."\n"; - echo ' <td><input type="password" name="password" /></td>'."\n"; + echo ' <td><input type="password" name="' . $this->_passwordField . '" /></td>'."\n"; echo '</tr>'."\n"; echo '<tr>'."\n"; echo ' <td colspan="2" bgcolor="#eeeeee"><input type="submit" /></td>'."\n";