diff --git a/lib/authentication/DBAuthenticator.inc b/lib/authentication/DBAuthenticator.inc index bebc344..b77569e 100644 --- a/lib/authentication/DBAuthenticator.inc +++ b/lib/authentication/DBAuthenticator.inc @@ -37,7 +37,6 @@ class DBAuthenticator extends Authenticator { function checkPassword($userName, $password) { global $default; - $sql = $default->db; $sTable = KTUtil::getTableName('users'); $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE username = ? AND password = ?"; $aParams = array($userName, md5($password)); @@ -58,13 +57,9 @@ class DBAuthenticator extends Authenticator { function getUser($sUserName, $aAttributes) { global $default; - $sql = $default->db; $sTable = KTUtil::getTableName('users'); $sQuery = "SELECT ";/*ok*/ - // build select - for ($i=0; $idb; $userName = $oUser->getUserName(); - $sQuery = "SELECT * FROM $default->users_table WHERE username = ? AND password = ?";/*ok*/ + $sTable = KTUtil::getTableName('users'); + $sQuery = "SELECT count(*) AS match_count FROM $sTable WHERE username = ? AND password = ?"; $aParams = array($userName, md5($password)); - if ($sql->query(array($sQuery, $aParams))) { - if ($sql->num_rows($sql) == "1") { - return true; - } else { - return false; - } - } else { - return false; + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'match_count'); + if (PEAR::isError($res)) { return false; } + else { + return ($res == 1); } + } /** @@ -268,28 +265,24 @@ class BuiltinAuthenticator extends Authenticator { * @return array containing the users found */ function getUser($sUserName, $aAttributes) { - global $default; - - $sql = $default->db; + $sTable = KTUtil::getTableName('users'); $sQuery = "SELECT ";/*ok*/ - // build select - for ($i=0; $iquery(array($sQuery, $aParams))) { - $aUserResults = array(); - while ($sql->next_record()) { - for ($i=0; $if($aAttributes[$i]); - } - } - return $aUserResults; - } else { - return false; + $res = DBUtil::getResultArray(array($sQuery, $aParams)); + if (PEAR::isError($res)) { + return false; } + + $aUserResults = array(); + foreach ($res as $aRow) { + foreach ($aAttributes as $sAttrName) { + $aUserResults[$sUserName][$sAttrName] = $aRow[$sAttrName]; + } + } + return $aUserResults; + } /** @@ -300,28 +293,24 @@ class BuiltinAuthenticator extends Authenticator { * @return array containing the users found */ function searchUsers($sUserNameSearch, $aAttributes) { - global $default; - - $sql = $default->db; - $sQuery = "SELECT ";/*ok*/ - // build select - for ($i=0; $iquery($sQuery)) { - $aUserResults = array(); - while ($sql->next_record()) { - $sUserName = $sql->f("username"); - for ($i=0; $if($aAttributes[$i]); - } + + $aUserResults = array(); + foreach ($res as $aRow) { + $sUserName = $aRow['username']; + foreach ($aAttributes as $sAttrName) { + $aUserResults[$sUserName][$sAttrName] = $aRow[$sAttrName]; } - return $aUserResults; - } else { - return false; } + return $aUserResults; } }