1
0
mirror of https://github.com/moparisthebest/user_sql synced 2024-11-21 16:55:02 -05:00

Added "Joomla" encryption type (thanks Frédéric France)

Added sort order and minimal caching (thanks Ed W)
This commit is contained in:
Andreas Boehler 2013-03-10 19:06:35 +01:00
parent ea2f18b22b
commit a767fe07a7
2 changed files with 26 additions and 3 deletions

View File

@ -24,7 +24,7 @@
<p><label for="sql_column_username"><?php echo $l->t('Username Column');?></label><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></p> <p><label for="sql_column_username"><?php echo $l->t('Username Column');?></label><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></p>
<p><label for="sql_column_password"><?php echo $l->t('Password Column');?></label><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></p> <p><label for="sql_column_password"><?php echo $l->t('Password Column');?></label><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></p>
<p><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label> <p><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label>
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()');?> <?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption');?>
<select id="crypt_type" name="crypt_type"> <select id="crypt_type" name="crypt_type">
<?php <?php
foreach ($crypt_types as $driver => $name): foreach ($crypt_types as $driver => $name):

View File

@ -3,9 +3,13 @@
/** /**
* ownCloud - user_sql * ownCloud - user_sql
* *
* @author Andreas Böhler * @author Andreas Böhler and contributors
* @copyright 2012/2013 Andreas Böhler <andreas (at) aboehler (dot) at> * @copyright 2012/2013 Andreas Böhler <andreas (at) aboehler (dot) at>
* *
* credits go to Ed W for several SQL injection fixes and caching support
* credits go to Frédéric France for providing Joomla support
* credits go to
*
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -200,7 +204,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
public function getUsers($search = '', $limit = null, $offset = null) public function getUsers($search = '', $limit = null, $offset = null)
{ {
OC_Log::write('OC_USER_SQL', "Entering getUsers() with Search: $search", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Entering getUsers() with Search: $search, Limit: $limit, Offset: $offset", OC_Log::DEBUG);
$users = array(); $users = array();
if(!$this->db_conn) if(!$this->db_conn)
{ {
@ -217,6 +221,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
$query .= " WHERE"; $query .= " WHERE";
$query .= " $this->sql_column_active = 1"; $query .= " $this->sql_column_active = 1";
} }
$query .= " ORDER BY $this->sql_column_username";
if($limit != null) if($limit != null)
{ {
$limit = intval($limit); $limit = intval($limit);
@ -264,6 +269,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
public function userExists($uid) public function userExists($uid)
{ {
static $cached_exists;
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
if(!$this->db_conn) if(!$this->db_conn)
{ {
@ -276,6 +282,10 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
$uid = strtolower($uid); $uid = strtolower($uid);
if ($uid === $cached_exists) {
OC_Log::write('OC_USER_SQL', "User exists (using cache), return true", OC_Log::DEBUG);
return true;
}
$query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid"; $query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid";
if($this->sql_column_active != '') if($this->sql_column_active != '')
$query .= " AND $this->sql_column_active = 1"; $query .= " AND $this->sql_column_active = 1";
@ -299,6 +309,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
else else
{ {
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG); OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
$cached_exists = $uid;
return true; return true;
} }
@ -395,6 +406,18 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
} }
$password = $row[0]; $password = $row[0];
} }
// The following is by Frédéric France
elseif($this->crypt_type == 'joomla')
{
$split_salt = preg_split ('/:/', $pw_db);
if(isset($split_salt[1]))
{
$salt = $split_salt[1];
}
$password = ($salt) ? md5($pw.$salt) : md5($pw);
$password.= ':'.$salt;
}
else { else {
OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR); OC_Log::write('OC_USER_SQL', "unknown/invalid crypt_type settings: $this->crypt_type", OC_Log::ERROR);