diff options
Diffstat (limited to 'application/libraries/Duser/drivers')
-rw-r--r-- | application/libraries/Duser/drivers/Duser_db.php | 12 | ||||
-rw-r--r-- | application/libraries/Duser/drivers/Duser_fluxbb.php | 53 |
2 files changed, 58 insertions, 7 deletions
diff --git a/application/libraries/Duser/drivers/Duser_db.php b/application/libraries/Duser/drivers/Duser_db.php index 1258ec585..a58b5a298 100644 --- a/application/libraries/Duser/drivers/Duser_db.php +++ b/application/libraries/Duser/drivers/Duser_db.php @@ -9,11 +9,13 @@ class Duser_db extends Duser_Driver { + /* FIXME: If you use this driver as a template, remove can_reset_password + * and can_register_new_users. These features require the DB driver and + * will NOT work with other drivers. + */ public $optional_functions = array( - 'username_exists', 'can_reset_password', 'can_register_new_users', - 'get_email', ); public function login($username, $password) @@ -26,11 +28,7 @@ class Duser_db extends Duser_Driver { WHERE `username` = ? ', array($username))->row_array(); - if (!isset($query["username"]) || $query["username"] !== $username) { - return false; - } - - if (!isset($query["password"])) { + if (empty($query)) { return false; } diff --git a/application/libraries/Duser/drivers/Duser_fluxbb.php b/application/libraries/Duser/drivers/Duser_fluxbb.php new file mode 100644 index 000000000..1790e830b --- /dev/null +++ b/application/libraries/Duser/drivers/Duser_fluxbb.php @@ -0,0 +1,53 @@ +<?php +/* + * Copyright 2013 Pierre Schmitz <pierre@archlinux.de> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +class Duser_fluxbb extends Duser_Driver { + + private $CI = null; + private $config = array(); + + function __construct() + { + $this->CI =& get_instance(); + $this->config = $this->CI->config->item('auth_fluxbb'); + } + + public function login($username, $password) + { + $query = $this->CI->db->query(' + SELECT username, id + FROM '.$this->config['database'].'.users + WHERE username = ? AND password = ? + ', array($username, sha1($password)))->row_array(); + + if (!empty($query)) { + return array( + 'username' => $query['username'], + 'userid' => $query['id'] + ); + } else { + return false; + } + } + + public function username_exists($username) + { + $query = $this->CI->db->query(' + SELECT id + FROM '.$this->config['database'].'.users + WHERE username = ? + ', array($username)); + + if ($query->num_rows() > 0) { + return true; + } else { + return false; + } + } +} |