mirror of https://github.com/nextcloud/server
Refactor `OC\Server::getHasher`
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
This commit is contained in:
parent
df1cd1ba7e
commit
f9ce6bfdff
|
@ -42,10 +42,10 @@ use OCP\Security\IHasher;
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* // Hashing a message
|
* // Hashing a message
|
||||||
* $hash = \OC::$server->getHasher()->hash('MessageToHash');
|
* $hash = \OC::$server->get(\OCP\Security\IHasher::class)->hash('MessageToHash');
|
||||||
* // Verifying a message - $newHash will contain the newly calculated hash
|
* // Verifying a message - $newHash will contain the newly calculated hash
|
||||||
* $newHash = null;
|
* $newHash = null;
|
||||||
* var_dump(\OC::$server->getHasher()->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
|
* var_dump(\OC::$server->get(\OCP\Security\IHasher::class)->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
|
||||||
* var_dump($newHash);
|
* var_dump($newHash);
|
||||||
*
|
*
|
||||||
* @package OC\Security
|
* @package OC\Security
|
||||||
|
|
|
@ -45,6 +45,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
|
use OCP\Security\IHasher;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
use OCP\Share\IProviderFactory;
|
use OCP\Share\IProviderFactory;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
@ -199,7 +200,7 @@ class ProviderFactory implements IProviderFactory {
|
||||||
$this->serverContainer->getActivityManager(),
|
$this->serverContainer->getActivityManager(),
|
||||||
$settingsManager,
|
$settingsManager,
|
||||||
$this->serverContainer->query(Defaults::class),
|
$this->serverContainer->query(Defaults::class),
|
||||||
$this->serverContainer->getHasher(),
|
$this->serverContainer->get(IHasher::class),
|
||||||
$this->serverContainer->get(IEventDispatcher::class),
|
$this->serverContainer->get(IEventDispatcher::class),
|
||||||
$this->serverContainer->get(IManager::class)
|
$this->serverContainer->get(IManager::class)
|
||||||
);
|
);
|
||||||
|
|
|
@ -50,6 +50,7 @@ use OCP\Cache\CappedMemoryCache;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
||||||
|
use OCP\Security\IHasher;
|
||||||
use OCP\User\Backend\ABackend;
|
use OCP\User\Backend\ABackend;
|
||||||
use OCP\User\Backend\ICheckPasswordBackend;
|
use OCP\User\Backend\ICheckPasswordBackend;
|
||||||
use OCP\User\Backend\ICountUsersBackend;
|
use OCP\User\Backend\ICountUsersBackend;
|
||||||
|
@ -130,7 +131,7 @@ class Database extends ABackend implements
|
||||||
$qb->insert($this->table)
|
$qb->insert($this->table)
|
||||||
->values([
|
->values([
|
||||||
'uid' => $qb->createNamedParameter($uid),
|
'uid' => $qb->createNamedParameter($uid),
|
||||||
'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)),
|
'password' => $qb->createNamedParameter(\OC::$server->get(IHasher::class)->hash($password)),
|
||||||
'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)),
|
'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -197,7 +198,7 @@ class Database extends ABackend implements
|
||||||
if ($this->userExists($uid)) {
|
if ($this->userExists($uid)) {
|
||||||
$this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
|
$this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
|
||||||
|
|
||||||
$hasher = \OC::$server->getHasher();
|
$hasher = \OC::$server->get(IHasher::class);
|
||||||
$hashedPassword = $hasher->hash($password);
|
$hashedPassword = $hasher->hash($password);
|
||||||
|
|
||||||
$return = $this->updatePassword($uid, $hashedPassword);
|
$return = $this->updatePassword($uid, $hashedPassword);
|
||||||
|
@ -353,7 +354,7 @@ class Database extends ABackend implements
|
||||||
if ($found && is_array($this->cache[$loginName])) {
|
if ($found && is_array($this->cache[$loginName])) {
|
||||||
$storedHash = $this->cache[$loginName]['password'];
|
$storedHash = $this->cache[$loginName]['password'];
|
||||||
$newHash = '';
|
$newHash = '';
|
||||||
if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) {
|
if (\OC::$server->get(IHasher::class)->verify($password, $storedHash, $newHash)) {
|
||||||
if (!empty($newHash)) {
|
if (!empty($newHash)) {
|
||||||
$this->updatePassword($loginName, $newHash);
|
$this->updatePassword($loginName, $newHash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,10 @@ namespace OCP\Security;
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* // Hashing a message
|
* // Hashing a message
|
||||||
* $hash = \OC::$server->getHasher()->hash('MessageToHash');
|
* $hash = \OC::$server->get(\OCP\Security\IHasher::class)->hash('MessageToHash');
|
||||||
* // Verifying a message - $newHash will contain the newly calculated hash
|
* // Verifying a message - $newHash will contain the newly calculated hash
|
||||||
* $newHash = null;
|
* $newHash = null;
|
||||||
* var_dump(\OC::$server->getHasher()->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
|
* var_dump(\OC::$server->get(\OCP\Security\IHasher::class)->verify('a', '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8', $newHash));
|
||||||
* var_dump($newHash);
|
* var_dump($newHash);
|
||||||
*
|
*
|
||||||
* @since 8.0.0
|
* @since 8.0.0
|
||||||
|
|
|
@ -70,7 +70,7 @@ class PublicKeyTokenProviderTest extends TestCase {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->mapper = $this->createMock(PublicKeyTokenMapper::class);
|
$this->mapper = $this->createMock(PublicKeyTokenMapper::class);
|
||||||
$this->hasher = \OC::$server->getHasher();
|
$this->hasher = \OC::$server->get(IHasher::class);
|
||||||
$this->crypto = \OC::$server->getCrypto();
|
$this->crypto = \OC::$server->getCrypto();
|
||||||
$this->config = $this->createMock(IConfig::class);
|
$this->config = $this->createMock(IConfig::class);
|
||||||
$this->config->method('getSystemValueInt')
|
$this->config->method('getSystemValueInt')
|
||||||
|
|
Loading…
Reference in New Issue