[Filebin-general] [PATCH] Add FluxBB authentication driver

Pierre Schmitz pierre at archlinux.de
Sun Sep 22 09:21:00 CEST 2013


To enable set:
	$config['authentication_driver'] = 'fluxbb';
	$config['auth_fluxbb'] = array('database' => 'fluxbb');

Signed-off-by: Pierre Schmitz <pierre at archlinux.de>
---
 application/libraries/Duser/Duser.php              |  2 +-
 .../libraries/Duser/drivers/Duser_fluxbb.php       | 57 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 application/libraries/Duser/drivers/Duser_fluxbb.php

diff --git a/application/libraries/Duser/Duser.php b/application/libraries/Duser/Duser.php
index 38ee967..07a1619 100644
--- a/application/libraries/Duser/Duser.php
+++ b/application/libraries/Duser/Duser.php
@@ -49,7 +49,7 @@ class Duser extends CI_Driver_Library {
 	protected $_adapter = null;
 
 	protected $valid_drivers = array(
-		'duser_db', 'duser_ldap'
+		'duser_db', 'duser_ldap', 'duser_fluxbb'
 	);
 
 	function __construct()
diff --git a/application/libraries/Duser/drivers/Duser_fluxbb.php b/application/libraries/Duser/drivers/Duser_fluxbb.php
new file mode 100644
index 0000000..8c8a0df
--- /dev/null
+++ b/application/libraries/Duser/drivers/Duser_fluxbb.php
@@ -0,0 +1,57 @@
+<?php
+/*
+ * Copyright 2013 Pierre Schmitz <pierre at archlinux.de>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+class Duser_fluxbb extends Duser_Driver {
+
+	public $optional_functions = array(
+		'username_exists',
+	);
+
+	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 LIKE ? 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 LIKE ?
+			', array($username));
+
+		if ($query->num_rows() > 0) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+}
-- 
1.8.4


More information about the Filebin-general mailing list