summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-03-15 15:08:32 +0100
committerGitHub <noreply@github.com>2024-03-15 15:08:32 +0100
commitf5e3fea2850ebdf84df3e6eb7431aae9847d5974 (patch)
tree1d4ab0bf5f17ff740a6a6ce1bf84fa842807b6ff
parent27defd7e51a29370e513679ff0bd30b3cc49834c (diff)
parentf9ce6bfdff10665d40400c80662e9b29a00d8b3f (diff)
downloadnextcloud-server-f5e3fea2850ebdf84df3e6eb7431aae9847d5974.tar.gz
nextcloud-server-f5e3fea2850ebdf84df3e6eb7431aae9847d5974.zip
Merge pull request #40138 from summersab/refactor/OC-Server-getHasher
-rw-r--r--lib/private/Security/Hasher.php4
-rw-r--r--lib/private/Share20/ProviderFactory.php3
-rw-r--r--lib/private/User/Database.php7
-rw-r--r--lib/public/Security/IHasher.php4
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php2
5 files changed, 11 insertions, 9 deletions
diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php
index 23747751053..196b58df2ce 100644
--- a/lib/private/Security/Hasher.php
+++ b/lib/private/Security/Hasher.php
@@ -42,10 +42,10 @@ use OCP\Security\IHasher;
*
* Usage:
* // 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
* $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);
*
* @package OC\Security
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index 6d052d04f01..1ef2afe0f49 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -46,6 +46,7 @@ use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IServerContainer;
+use OCP\Security\IHasher;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
@@ -200,7 +201,7 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getActivityManager(),
$settingsManager,
$this->serverContainer->query(Defaults::class),
- $this->serverContainer->getHasher(),
+ $this->serverContainer->get(IHasher::class),
$this->serverContainer->get(IEventDispatcher::class),
$this->serverContainer->get(IManager::class)
);
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php
index 9ef1bc67a58..55d0183ce52 100644
--- a/lib/private/User/Database.php
+++ b/lib/private/User/Database.php
@@ -50,6 +50,7 @@ use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\Security\Events\ValidatePasswordPolicyEvent;
+use OCP\Security\IHasher;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICheckPasswordBackend;
use OCP\User\Backend\ICountUsersBackend;
@@ -130,7 +131,7 @@ class Database extends ABackend implements
$qb->insert($this->table)
->values([
'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)),
]);
@@ -197,7 +198,7 @@ class Database extends ABackend implements
if ($this->userExists($uid)) {
$this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
- $hasher = \OC::$server->getHasher();
+ $hasher = \OC::$server->get(IHasher::class);
$hashedPassword = $hasher->hash($password);
$return = $this->updatePassword($uid, $hashedPassword);
@@ -353,7 +354,7 @@ class Database extends ABackend implements
if ($found && is_array($this->cache[$loginName])) {
$storedHash = $this->cache[$loginName]['password'];
$newHash = '';
- if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) {
+ if (\OC::$server->get(IHasher::class)->verify($password, $storedHash, $newHash)) {
if (!empty($newHash)) {
$this->updatePassword($loginName, $newHash);
}
diff --git a/lib/public/Security/IHasher.php b/lib/public/Security/IHasher.php
index 7c4d743002c..f64bb064422 100644
--- a/lib/public/Security/IHasher.php
+++ b/lib/public/Security/IHasher.php
@@ -37,10 +37,10 @@ namespace OCP\Security;
*
* Usage:
* // 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
* $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);
*
* @since 8.0.0
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
index 69894f14855..99d058f22a6 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
@@ -70,7 +70,7 @@ class PublicKeyTokenProviderTest extends TestCase {
parent::setUp();
$this->mapper = $this->createMock(PublicKeyTokenMapper::class);
- $this->hasher = \OC::$server->getHasher();
+ $this->hasher = \OC::$server->get(IHasher::class);
$this->crypto = \OC::$server->getCrypto();
$this->config = $this->createMock(IConfig::class);
$this->config->method('getSystemValueInt')