summaryrefslogtreecommitdiffstats
path: root/application/libraries/Duser/drivers/Duser_fluxbb.php
blob: 1790e830bd6af6412f3c2869c98d64812b3d5d39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
		}
	}
}