cvs: pear /Auth/Container MDB2.php
| From: | Lorenzo Alberton | Date: | Sun, 04 Jul 2004 20:31:55 +0000 |
| Subject: | cvs: pear /Auth/Container MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-21503@lists.php.net to get a copy of this message | ||
quipo Sun Jul 4 16:31:55 2004 EDT
Modified files:
/pear/Auth/Container MDB2.php
Log:
- sync with DB container, support for challenge support on login
- some code tweaks
http://cvs.php.net/diff.php/pear/Auth/Container/MDB2.php?r1=1.2&r2=1.3&ty=u
Index: pear/Auth/Container/MDB2.php
diff -u pear/Auth/Container/MDB2.php:1.2 pear/Auth/Container/MDB2.php:1.3
--- pear/Auth/Container/MDB2.php:1.2 Mon Apr 26 15:50:31 2004
+++ pear/Auth/Container/MDB2.php Sun Jul 4 16:31:54 2004
@@ -16,7 +16,7 @@
// | Author: Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.2 2004/04/26 19:50:31 toby Exp $
+// $Id: MDB2.php,v 1.3 2004/07/04 20:31:54 quipo Exp $
//
require_once 'Auth/Container.php';
@@ -30,7 +30,7 @@
*
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @package Auth
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
class Auth_Container_MDB2 extends Auth_Container
{
@@ -91,7 +91,7 @@
function _connect($dsn)
{
if (is_string($dsn) || is_array($dsn)) {
- $this->db =& MDB2::connect($dsn);
+ $this->db =& MDB2::connect($dsn, $this->options['db_options']);
} elseif (is_a($dsn, 'MDB2_Driver_Common')) {
$this->db = $dsn;
} elseif (is_object($dsn) && MDB2::isError($dsn)) {
@@ -126,6 +126,9 @@
*/
function _prepare()
{
+ if (is_a($this->db, 'MDB2_Driver_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();
@@ -243,6 +250,19 @@
$this->activeUser = '';
return false;
}
+
+ // Perform trimming here before the hashing
+ $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(trim($password, "\r\n"),
trim($res[$this->options['passwordcol']],
"\r\n"),
$this->options['cryptType'])) {
@@ -283,7 +303,7 @@
$retVal = array();
- // Find if db_fileds contains a *, i so assume all col are selected
+ //Check if db_fields contains a *, if so assume all columns are selected
if (strstr($this->options['db_fields'], '*')) {
$sql_from = '*';
} else {
@@ -331,6 +351,8 @@
$cryptFunction = 'md5';
}
+ $password = $cryptFunction($password);
+
$additional_key = '';
$additional_value = '';
@@ -347,7 +369,7 @@
$this->options['passwordcol'],
$additional_key,
$this->db->quote($username, 'text'),
- $this->db->quote($cryptFunction($password), 'text'),
+ $this->db->quote($password, 'text'),
$additional_value
);
@@ -392,8 +414,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)
{
@@ -405,6 +427,8 @@
$cryptFunction = 'md5';
}
+ $password = $cryptFunction($password);
+
$query = sprintf("UPDATE %s SET %s = %s WHERE %s = %s",
$this->options['table'],
$this->options['passwordcol'],
@@ -422,6 +446,35 @@
}
// }}}
+ // {{{ 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'];
+ }
+
+ // }}}
}
-?>
+?>
\ No newline at end of file