Adding SALT from DB and new Algorithm to be connected with HumHub
https://github.com/nextcloud/user_sql/pull/42
This commit is contained in:
@@ -274,6 +274,10 @@ final class UserBackend extends Backend
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($user->salt !== null) {
|
||||
$password .= $user->salt;
|
||||
}
|
||||
|
||||
$isCorrect = $passwordAlgorithm->checkPassword(
|
||||
$password, $user->password
|
||||
);
|
||||
@@ -417,13 +421,17 @@ final class UserBackend extends Backend
|
||||
return false;
|
||||
}
|
||||
|
||||
$passwordHash = $passwordAlgorithm->getPasswordHash($password);
|
||||
if ($passwordHash === false) {
|
||||
$user = $this->userRepository->findByUid($uid);
|
||||
if (!($user instanceof User)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->userRepository->findByUid($uid);
|
||||
if (!($user instanceof User)) {
|
||||
if ($user->salt !== null) {
|
||||
$password .= $user->salt;
|
||||
}
|
||||
|
||||
$passwordHash = $passwordAlgorithm->getPasswordHash($password);
|
||||
if ($passwordHash === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,5 +51,6 @@ final class DB
|
||||
const USER_HOME_COLUMN = "db.table.user.column.home";
|
||||
const USER_NAME_COLUMN = "db.table.user.column.name";
|
||||
const USER_PASSWORD_COLUMN = "db.table.user.column.password";
|
||||
const USER_SALT_COLUMN = "db.table.user.column.salt";
|
||||
const USER_UID_COLUMN = "db.table.user.column.uid";
|
||||
}
|
||||
|
||||
58
lib/Crypto/SHA512Whirlpool.php
Normal file
58
lib/Crypto/SHA512Whirlpool.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Nextcloud - user_sql
|
||||
*
|
||||
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace OCA\UserSQL\Crypto;
|
||||
|
||||
use OCP\IL10N;
|
||||
|
||||
/**
|
||||
* SHA512 Whirlpool hashing implementation.
|
||||
*
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*/
|
||||
class SHA512Whirlpool extends AbstractAlgorithm
|
||||
{
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param IL10N $localization The localization service.
|
||||
*/
|
||||
public function __construct(IL10N $localization)
|
||||
{
|
||||
parent::__construct($localization);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getPasswordHash($password)
|
||||
{
|
||||
return hash('sha512', hash('whirlpool', $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getAlgorithmName()
|
||||
{
|
||||
return "SHA512 Whirlpool";
|
||||
}
|
||||
}
|
||||
@@ -56,4 +56,8 @@ class User
|
||||
* @var bool Can user change its avatar.
|
||||
*/
|
||||
public $avatar;
|
||||
/**
|
||||
* @var string The password's salt.
|
||||
*/
|
||||
public $salt;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class QueryProvider implements \ArrayAccess
|
||||
$uHome = $this->properties[DB::USER_HOME_COLUMN];
|
||||
$uName = $this->properties[DB::USER_NAME_COLUMN];
|
||||
$uPassword = $this->properties[DB::USER_PASSWORD_COLUMN];
|
||||
$uSalt = $this->properties[DB::USER_SALT_COLUMN];
|
||||
$uUID = $this->properties[DB::USER_UID_COLUMN];
|
||||
|
||||
$ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN];
|
||||
@@ -92,7 +93,8 @@ class QueryProvider implements \ArrayAccess
|
||||
(empty($uEmail) ? "null" : $uEmail) . " AS email, " .
|
||||
(empty($uHome) ? "null" : $uHome) . " AS home, " .
|
||||
(empty($uActive) ? "true" : $uActive) . " AS active, " .
|
||||
(empty($uAvatar) ? "false" : $uAvatar) . " AS avatar";
|
||||
(empty($uAvatar) ? "false" : $uAvatar) . " AS avatar, " .
|
||||
(empty($uSalt) ? "null" : $uSalt) . " AS salt";
|
||||
|
||||
$this->queries = [
|
||||
Query::BELONGS_TO_ADMIN =>
|
||||
|
||||
Reference in New Issue
Block a user