aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authoryemkareems <yemkareems@gmail.com>2024-10-28 11:22:36 +0530
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-10-28 12:34:36 +0000
commitbe581d7ce8727cd63a80be2646efb053a4ef64ab (patch)
tree8094d9e38a41db36501493da58f125f6240d9013 /lib/private
parent70d9e4a229f638c37c7c721efcb222d90568311b (diff)
downloadnextcloud-server-be581d7ce8727cd63a80be2646efb053a4ef64ab.tar.gz
nextcloud-server-be581d7ce8727cd63a80be2646efb053a4ef64ab.zip
fix: encrypt and store password, decrypt and retrieve the same
Signed-off-by: yemkareems <yemkareems@gmail.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Authentication/LoginCredentials/Store.php7
-rw-r--r--lib/private/Server.php3
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/private/Authentication/LoginCredentials/Store.php b/lib/private/Authentication/LoginCredentials/Store.php
index 2e00ac211c1..5a1aad6c743 100644
--- a/lib/private/Authentication/LoginCredentials/Store.php
+++ b/lib/private/Authentication/LoginCredentials/Store.php
@@ -28,6 +28,7 @@ namespace OC\Authentication\LoginCredentials;
use OC\Authentication\Exceptions\PasswordlessTokenException;
use OC\Authentication\Token\IProvider;
+use OC\Security\Crypto;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Authentication\Exceptions\InvalidTokenException;
use OCP\Authentication\LoginCredentials\ICredentials;
@@ -47,12 +48,16 @@ class Store implements IStore {
/** @var IProvider|null */
private $tokenProvider;
+ /** @var Crypto|null */
+ private $crypto;
+
public function __construct(ISession $session,
LoggerInterface $logger,
IProvider $tokenProvider = null) {
$this->session = $session;
$this->logger = $logger;
$this->tokenProvider = $tokenProvider;
+ $this->crypto = $crypto;
Util::connectHook('OC_User', 'post_login', $this, 'authenticate');
}
@@ -63,6 +68,7 @@ class Store implements IStore {
* @param array $params
*/
public function authenticate(array $params) {
+ $params['password'] = $this->crypto->encrypt((string)$params['password']);
$this->session->set('login_credentials', json_encode($params));
}
@@ -109,6 +115,7 @@ class Store implements IStore {
if ($trySession && $this->session->exists('login_credentials')) {
/** @var array $creds */
$creds = json_decode($this->session->get('login_credentials'), true);
+ $creds['password'] = $this->crypto->decrypt($creds['password']);
return new Credentials(
$creds['uid'],
$creds['loginName'] ?? $this->session->get('loginname') ?? $creds['uid'], // Pre 20 didn't have a loginName property, hence fall back to the session value and then to the UID
diff --git a/lib/private/Server.php b/lib/private/Server.php
index c5fd8327c41..7e32a667c8a 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -512,7 +512,8 @@ class Server extends ServerContainer implements IServerContainer {
$tokenProvider = null;
}
$logger = $c->get(LoggerInterface::class);
- return new Store($session, $logger, $tokenProvider);
+ $crypto = $c->get(Crypto::class);
+ return new Store($session, $logger, $tokenProvider, $crypto);
});
$this->registerAlias(IStore::class, Store::class);
$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);