1
0
mirror of https://github.com/moparisthebest/user_sql synced 2025-02-16 06:50:16 -05:00

Add support for SSHA256 (thanks to Dominik Grothaus)

This commit is contained in:
Andreas Boehler 2014-12-29 10:38:20 +01:00
parent e36ee5bfd8
commit bbbe44665e
2 changed files with 14 additions and 1 deletions

View File

@ -44,7 +44,7 @@ $cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
<tr><td><label for="sql_column_password"><?php echo $l -> t('Password Column'); ?></label></td><td><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></td></tr> <tr><td><label for="sql_column_password"><?php echo $l -> t('Password Column'); ?></label></td><td><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></td></tr>
<tr><td><label for="sql_column_displayname"><?php echo $l -> t('Real Name Column'); ?></label></td><td><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></td></tr> <tr><td><label for="sql_column_displayname"><?php echo $l -> t('Real Name Column'); ?></label></td><td><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></td></tr>
<tr><td><label for="crypt_type"><?php echo $l -> t('Encryption Type'); ?></label></td> <tr><td><label for="crypt_type"><?php echo $l -> t('Encryption Type'); ?></label></td>
<?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', 'joomla2' => 'Joomla > 2.5.18 phpass'); ?> <?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', 'joomla2' => 'Joomla > 2.5.18 phpass', 'ssha256' => 'Salted SSHA256'); ?>
<td><select id="crypt_type" name="crypt_type"> <td><select id="crypt_type" name="crypt_type">
<?php <?php
foreach ($crypt_types as $driver => $name): foreach ($crypt_types as $driver => $name):

View File

@ -9,6 +9,7 @@
* credits go to Ed W for several SQL injection fixes and caching support * 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 Frédéric France for providing Joomla support
* credits go to Mark Jansenn for providing Joomla 2.5.18+ / 3.2.1+ support * credits go to Mark Jansenn for providing Joomla 2.5.18+ / 3.2.1+ support
* credits go to Dominik Grothaus for providing SSHA256 support and fixing a few bugs
* *
* 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
@ -538,6 +539,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface
} }
$password = ($salt) ? md5($pw . $salt) : md5($pw); $password = ($salt) ? md5($pw . $salt) : md5($pw);
$password .= ':' . $salt; $password .= ':' . $salt;
}
elseif($this-> crypt_type == 'ssha256')
{
$salted_password = base64_decode(preg_replace('/{SSHA256}/i','',$pw_db));
$salt = substr($salted_password,-(strlen($salted_password)-32));
$password = $this->ssha256($pw,$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);
@ -631,6 +639,11 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface
return $salt; return $salt;
} }
private function ssha256($pw, $salt)
{
return '{SSHA256}'.base64_encode(hash('sha256',$pw.$salt,true).$salt);
}
private function pahex2bin($str) private function pahex2bin($str)
{ {
if(function_exists('hex2bin')) if(function_exists('hex2bin'))