cvs: pear /Auth/Container MDB.php
| From: | Lorenzo Alberton | Date: | Sun, 04 Jul 2004 19:59:34 +0000 |
| Subject: | cvs: pear /Auth/Container MDB.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-21502@lists.php.net to get a copy of this message | ||
quipo Sun Jul 4 15:59:34 2004 EDT
Modified files:
/pear/Auth/Container MDB.php
Log:
- sync with DB container, support for challenge support on login
- some code tweaks
http://cvs.php.net/diff.php/pear/Auth/Container/MDB.php?r1=1.15&r2=1.16&ty=u
Index: pear/Auth/Container/MDB.php
diff -u pear/Auth/Container/MDB.php:1.15 pear/Auth/Container/MDB.php:1.16
--- pear/Auth/Container/MDB.php:1.15 Tue Mar 30 12:39:04 2004
+++ pear/Auth/Container/MDB.php Sun Jul 4 15:59:34 2004
@@ -16,7 +16,7 @@
// | Author: Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB.php,v 1.15 2004/03/30 17:39:04 quipo Exp $
+// $Id: MDB.php,v 1.16 2004/07/04 19:59:34 quipo Exp $
//
require_once 'Auth/Container.php';
@@ -30,7 +30,7 @@
*
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @package Auth
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
class Auth_Container_MDB extends Auth_Container
{
@@ -91,8 +91,8 @@
function _connect($dsn)
{
if (is_string($dsn) || is_array($dsn)) {
- $this->db =& MDB::Connect($dsn);
- } elseif (get_parent_class($dsn) == "mdb_common") {
+ $this->db =& MDB::connect($dsn, $this->options['db_options']);
+ } elseif (is_a($dsn, 'mdb_common')) {
$this->db = $dsn;
} elseif (is_object($dsn) && MDB::isError($dsn)) {
return PEAR::raiseError($dsn->getMessage(), $dsn->code);
@@ -126,6 +126,9 @@
*/
function _prepare()
{
+ if (is_a($this->db, 'mdb_common')) {
+ return true;
+ }
return $this->_connect($this->options['dsn']);
}
@@ -170,6 +173,7 @@
$this->options['dsn'] = '';
$this->options['db_fields'] = '';
$this->options['cryptType'] = 'md5';
+ $this->options['db_options'] = array();
}
// }}}
@@ -212,9 +216,12 @@
*
* @param string Username
* @param string Password
+ * @param boolean If true password is secured using a md5 hash
+ * the frontend and auth are responsible for making sure the container
supports
+ * challenge response password authentication
* @return mixed Error object or boolean
*/
- function fetchData($username, $password)
+ function fetchData($username, $password, $isChallengeResponse=false)
{
// Prepare for a database query
$err = $this->_prepare();
@@ -245,8 +252,21 @@
$this->activeUser = '';
return false;
}
- if ($this->verifyPassword(trim($password, "\r\n"),
- trim($res[$this->options['passwordcol']],
"\r\n"),
+
+ // Perform trimming here before the hashihg
+ $password = trim($password, "\r\n");
+ $res[$this->options['passwordcol']] =
trim($res[$this->options['passwordcol']], "\r\n");
+ // If using Challenge Response md5 the pass with the secret
+ if ($isChallengeResponse) {
+ $res[$this->options['passwordcol']] =
+
md5($res[$this->options['passwordcol']].$this->_auth_obj->session['loginchallenege']);
+ // UGLY cannot avoid without modifying verifyPassword
+ if ($this->options['cryptType'] == 'md5') {
+ $res[$this->options['passwordcol']] =
md5($res[$this->options['passwordcol']]);
+ }
+ }
+ if ($this->verifyPassword($password,
+ $res[$this->options['passwordcol']],
$this->options['cryptType'])) {
// Store additional field values in the session
foreach ($res as $key => $value) {
@@ -262,7 +282,6 @@
Auth::setAuthData($key, $value);
}
}
-
return true;
}
@@ -285,7 +304,7 @@
$retVal = array();
- // Find if db_fileds contains a *, i so assume all col are selected
+ //Check if db_fileds contains a *, if so assume all columns are selected
if (strstr($this->options['db_fields'], '*')) {
$sql_from = '*';
} else {
@@ -334,6 +353,8 @@
$cryptFunction = 'md5';
}
+ $password = $cryptFunction($password);
+
$additional_key = '';
$additional_value = '';
@@ -350,7 +371,7 @@
$this->options['passwordcol'],
$additional_key,
$this->db->getTextValue($username),
- $this->db->getTextValue($cryptFunction($password)),
+ $this->db->getTextValue($password),
$additional_value
);
@@ -395,8 +416,8 @@
/**
* Change password for user in the storage container
*
- * @param string Username
- * @param string The new password
+ * @param string Username
+ * @param string The new password (plain text)
*/
function changePassword($username, $password)
{
@@ -408,6 +429,8 @@
$cryptFunction = 'md5';
}
+ $password = $cryptFunction($password);
+
$query = sprintf("UPDATE %s SET %s = %s WHERE %s = %s",
$this->options['table'],
$this->options['passwordcol'],
@@ -422,6 +445,35 @@
return PEAR::raiseError($res->getMessage(), $res->code);
}
return true;
+ }
+
+ // }}}
+ // {{{ supportsChallengeResponse()
+
+ /**
+ * Check if challenge response is supported
+ *
+ * @return boolean
+ */
+ function supportsChallengeResponse()
+ {
+ if ($this->options['cryptType'] == 'md5' ||
$this->options['cryptType'] == 'none' ||
$this->options['cryptType'] == '') {
+ return true;
+ }
+ return false;
+ }
+
+ // }}}
+ // {{{ getCryptType()
+
+ /**
+ * Get the crypt function name
+ *
+ * @return string Function used to crypt the password
+ */
+ function getCryptType()
+ {
+ return $this->options['cryptType'];
}
// }}}