summaryrefslogtreecommitdiffstats
path: root/application/libraries/Duser/drivers/Duser_db.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-01-30 22:31:11 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-01-30 22:31:11 +0100
commitf8ac2f6582001bfa3b42ac4fbdc77ff97137a8f8 (patch)
treecc6979a56bd458546582b7da3c69bf0ec5f8af82 /application/libraries/Duser/drivers/Duser_db.php
parente8d30fa25470f3912c0d4e8629fc7b764aae1c72 (diff)
Modularize authentication system
This allows to easily add LDAP and other support. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/libraries/Duser/drivers/Duser_db.php')
-rw-r--r--application/libraries/Duser/drivers/Duser_db.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/application/libraries/Duser/drivers/Duser_db.php b/application/libraries/Duser/drivers/Duser_db.php
new file mode 100644
index 000000000..806b0d150
--- /dev/null
+++ b/application/libraries/Duser/drivers/Duser_db.php
@@ -0,0 +1,63 @@
+<?php
+/*
+ * Copyright 2013 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under GPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+class Duser_db extends Duser_Driver {
+
+ public $optional_functions = array(
+ 'username_exists',
+ 'can_reset_password',
+ 'can_register_new_users'
+ );
+
+ public function login($username, $password)
+ {
+ $CI =& get_instance();
+
+ $query = $CI->db->query('
+ SELECT username, id, password
+ FROM `users`
+ WHERE `username` = ?
+ ', array($username))->row_array();
+
+ if (!isset($query["username"]) || $query["username"] !== $username) {
+ return false;
+ }
+
+ if (!isset($query["password"])) {
+ return false;
+ }
+
+ if (crypt($password, $query["password"]) === $query["password"]) {
+ return array(
+ "username" => $username,
+ "userid" => $query["id"]
+ );
+ } else {
+ return false;
+ }
+ }
+
+ public function username_exists($username)
+ {
+ $CI =& get_instance();
+
+ $query = $CI->db->query("
+ SELECT id
+ FROM users
+ WHERE username = ?
+ ", array($username));
+
+ if ($query->num_rows() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}