Skip to content

EspoCRM – Open Source CRM Application

Auth token password version (#3670)

Yurii Kuznietsov367ec9cd2110
diff --git a/application/Espo/Core/Authentication/AuthToken/AuthToken.php b/application/Espo/Core/Authentication/AuthToken/AuthToken.php
index 99b8ed48f1..91c4cc4830 100644
--- a/application/Espo/Core/Authentication/AuthToken/AuthToken.php
+++ b/application/Espo/Core/Authentication/AuthToken/AuthToken.php
@@ -60,8 +60,9 @@ interface AuthToken
public function isActive(): bool;
/**
- * Get a password hash. If a password hash is not stored in token, then return NULL.
- * If you store auth tokens remotely it's reasonable to avoid hashes being sent.
+ * Get the password version. If the password version is not stored in token, then return NULL.
+ *
+ * @since 10.0.0
*/
- public function getHash(): ?string;
+ public function getPasswordVersion(): ?int;
}
diff --git a/application/Espo/Core/Authentication/AuthToken/Data.php b/application/Espo/Core/Authentication/AuthToken/Data.php
index 5b263dacd0..86e404f807 100644
--- a/application/Espo/Core/Authentication/AuthToken/Data.php
+++ b/application/Espo/Core/Authentication/AuthToken/Data.php
@@ -41,9 +41,9 @@ class Data
{
private string $userId;
private ?string $portalId = null;
- private ?string $hash = null;
private ?string $ipAddress = null;
private bool $createSecret = false;
+ private ?int $passwordVersion = null;
private function __construct()
{}
@@ -65,19 +65,21 @@ class Data
}
/**
- * A hash.
+ * An ID address.
*/
- public function getHash(): ?string
+ public function getIpAddress(): ?string
{
- return $this->hash;
+ return $this->ipAddress;
}
/**
- * An ID address.
+ * A password version.
+ *
+ * @since 10.0.0
*/
- public function getIpAddress(): ?string
+ public function getPasswordVersion(): ?int
{
- return $this->ipAddress;
+ return $this->passwordVersion;
}
/**
@@ -92,7 +94,7 @@ class Data
* @param array{
* userId: string,
* portalId?: ?string,
- * hash?: ?string,
+ * passwordVersion?: ?int,
* ipAddress?: ?string,
* createSecret?: ?bool,
* } $data
@@ -109,9 +111,9 @@ class Data
$obj->userId = $userId;
$obj->portalId = $data['portalId'] ?? null;
- $obj->hash = $data['hash'] ?? null;
$obj->ipAddress = $data['ipAddress'] ?? null;
$obj->createSecret = $data['createSecret'] ?? false;
+ $obj->passwordVersion = $data['passwordVersion'] ?? null;
return $obj;
}
diff --git a/application/Espo/Core/Authentication/AuthToken/EspoManager.php b/application/Espo/Core/Authentication/AuthToken/EspoManager.php
index add9ce4394..c1f0971517 100644
--- a/application/Espo/Core/Authentication/AuthToken/EspoManager.php
+++ b/application/Espo/Core/Authentication/AuthToken/EspoManager.php
@@ -31,6 +31,7 @@ namespace Espo\Core\Authentication\AuthToken;
use Espo\Core\Name\Field;
use Espo\ORM\EntityManager;
+use Espo\ORM\Name\Attribute;
use Espo\ORM\Repository\RDBRepository;
use Espo\Entities\AuthToken as AuthTokenEntity;
@@ -50,7 +51,7 @@ class EspoManager implements Manager
/** @var RDBRepository<AuthTokenEntity> */
private RDBRepository $repository;
- private const TOKEN_RANDOM_LENGTH = 16;
+ private const int TOKEN_RANDOM_LENGTH = 16;
public function __construct(EntityManager $entityManager)
{
@@ -61,13 +62,14 @@ class EspoManager implements Manager
{
return $this->repository
->select([
- 'id',
+ Attribute::ID,
'isActive',
'token',
'secret',
'userId',
'portalId',
'hash',
+ AuthTokenEntity::FIELD_PASSWORD_VERSION,
Field::CREATED_AT,
'lastAccess',
Field::MODIFIED_AT,
@@ -83,7 +85,7 @@ class EspoManager implements Manager
$authToken
->setUserId($data->getUserId())
->setPortalId($data->getPortalId())
- ->setHash($data->getHash())
+ ->setPasswordVersion($data->getPasswordVersion())
->setIpAddress($data->getIpAddress())
->setToken($this->generateToken())
->setLastAccessNow();
diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.php
index db6329c3e4..529a9fac6f 100644
--- a/application/Espo/Core/Authentication/Authentication.php
+++ b/application/Espo/Core/Authentication/Authentication.php
@@ -67,13 +67,13 @@ use RuntimeException;
*/
class Authentication
{
- private const LOGOUT_USERNAME = '**logout';
+ private const string LOGOUT_USERNAME = '**logout';
- private const HEADER_CREATE_TOKEN_SECRET = 'Espo-Authorization-Create-Token-Secret';
- private const HEADER_ANOTHER_USER = 'X-Another-User';
- private const HEADER_LOGOUT_REDIRECT_URL = 'X-Logout-Redirect-Url';
+ private const string HEADER_CREATE_TOKEN_SECRET = 'Espo-Authorization-Create-Token-Secret';
+ private const string HEADER_ANOTHER_USER = 'X-Another-User';
+ private const string HEADER_LOGOUT_REDIRECT_URL = 'X-Logout-Redirect-Url';
- private const COOKIE_AUTH_TOKEN_SECRET = 'auth-token-secret';
+ private const string COOKIE_AUTH_TOKEN_SECRET = 'auth-token-secret';
public function __construct(
private ApplicationUser $applicationUser,
@@ -88,7 +88,7 @@ class Authentication
private LogoutFactory $logoutFactory,
private MethodProvider $methodProvider,
private Util $util,
- private LanguageProxy $language
+ private LanguageProxy $language,
) {}
/**
@@ -480,13 +480,12 @@ class Authentication
$request->getHeader(self::HEADER_CREATE_TOKEN_SECRET) === 'true' &&
!$this->configDataProvider->isAuthTokenSecretDisabled();
- $password = $user->getPassword();
$ipAddress = $this->util->obtainIpFromRequest($request);
$authTokenData = AuthTokenData::create([
- 'hash' => $password,
'ipAddress' => $ipAddress,
'userId' => $user->getId(),
+ 'passwordVersion' => $user->getPasswordVersion(),
'portalId' => $this->isPortal() ? $this->getPortal()->getId() : null,
'createSecret' => $createSecret,
]);
@@ -736,10 +735,9 @@ class Authentication
private function getUsernameByAuthToken(AuthToken $authToken): ?string
{
- /** @var ?User $user */
$user = $this->entityManager
- ->getRDBRepository(User::ENTITY_TYPE)
- ->select(['userName'])
+ ->getRDBRepositoryByClass(User::class)
+ ->select([User::FIELD_USER_NAME])
->where([Attribute::ID => $authToken->getUserId()])
->findOne();
@@ -766,10 +764,9 @@ class Authentication
return [null, FailReason::ANOTHER_USER_NOT_ALLOWED];
}
- /** @var ?User $loggedUser */
$loggedUser = $this->entityManager
- ->getRDBRepository(User::ENTITY_TYPE)
- ->where(['userName' => $username])
+ ->getRDBRepositoryByClass(User::class)
+ ->where([User::FIELD_USER_NAME => $username])
->findOne();
if (!$loggedUser) {
diff --git a/application/Espo/Core/Authentication/Helper/UserFinder.php b/application/Espo/Core/Authentication/Helper/UserFinder.php
index 91a6cd6eb9..a34e5bfef4 100644
--- a/application/Espo/Core/Authentication/Helper/UserFinder.php
+++ b/application/Espo/Core/Authentication/Helper/UserFinder.php
@@ -33,9 +33,19 @@ use Espo\Core\Authentication\Logins\ApiKey;
use Espo\Core\Authentication\Logins\Hmac;
use Espo\ORM\EntityManager;
use Espo\Entities\User;
+use Espo\ORM\Name\Attribute;
+/**
+ * @internal
+ */
class UserFinder
{
+ /** @var string[] */
+ private const array FORBIDDEN_USER_TYPE_LIST = [
+ User::TYPE_API,
+ User::TYPE_SYSTEM,
+ ];
+
public function __construct(private EntityManager $entityManager)
{}
@@ -44,22 +54,22 @@ class UserFinder
return $this->entityManager
->getRDBRepositoryByClass(User::class)
->where([
- 'userName' => $username,
- 'type!=' => [User::TYPE_API, User::TYPE_SYSTEM],
+ User::FIELD_USER_NAME => $username,
+ User::FIELD_TYPE . '!=' => self::FORBIDDEN_USER_TYPE_LIST,
])
->findOne();
}
- public function findByIdAndHash(string $username, string $id, ?string $hash): ?User
+ public function findByAuthTokenData(string $username, string $id, ?int $passwordVersion): ?User
{
$where = [
- 'userName' => $username,
- 'id' => $id,
- 'type!=' => [User::TYPE_API, User::TYPE_SYSTEM],
+ User::FIELD_USER_NAME => $username,
+ Attribute::ID => $id,
+ User::FIELD_TYPE . '!=' => self::FORBIDDEN_USER_TYPE_LIST,
];
- if ($hash) {
- $where['password'] = $hash;
+ if ($passwordVersion !== null) {
+ $where[User::FIELD_PASSWORD_VERSION] = $passwordVersion;
}
return $this->entityManager
@@ -73,7 +83,7 @@ class UserFinder
return $this->entityManager
->getRDBRepositoryByClass(User::class)
->where([
- 'type' => User::TYPE_API,
+ User::FIELD_TYPE => User::TYPE_API,
'apiKey' => $apiKey,
'authMethod' => Hmac::NAME,
])
@@ -85,7 +95,7 @@ class UserFinder
return $this->entityManager
->getRDBRepositoryByClass(User::class)
->where([
- 'type' => User::TYPE_API,
+ User::FIELD_TYPE => User::TYPE_API,
'apiKey' => $apiKey,
'authMethod' => ApiKey::NAME,
])
diff --git a/application/Espo/Core/Authentication/Logins/Espo.php b/application/Espo/Core/Authentication/Logins/Espo.php
index 63d3cb2951..8ca92dac99 100644
--- a/application/Espo/Core/Authentication/Logins/Espo.php
+++ b/application/Espo/Core/Authentication/Logins/Espo.php
@@ -30,16 +30,18 @@
namespace Espo\Core\Authentication\Logins;
use Espo\Core\Api\Request;
+use Espo\Core\Authentication\AuthToken\AuthToken;
use Espo\Core\Authentication\Helper\UserFinder;
use Espo\Core\Authentication\Login;
use Espo\Core\Authentication\Login\Data;
use Espo\Core\Authentication\Result;
use Espo\Core\Authentication\Result\FailReason;
use Espo\Core\Utils\PasswordHash;
+use Espo\Entities\User;
class Espo implements Login
{
- public const NAME = 'Espo';
+ public const string NAME = 'Espo';
public function __construct(
private UserFinder $userFinder,
@@ -61,7 +63,7 @@ class Espo implements Login
}
if ($authToken) {
- $user = $this->userFinder->findByIdAndHash($username, $authToken->getUserId(), $authToken->getHash());
+ $user = $this->findUserByAuthTokenData($username, $authToken);
} else {
$user = $this->userFinder->find($username);
@@ -80,4 +82,11 @@ class Espo implements Login
return Result::success($user);
}
+
+
+ private function findUserByAuthTokenData(string $username, AuthToken $authToken): ?User
+ {
+ return $this->userFinder
+ ->findByAuthTokenData($username, $authToken->getUserId(), $authToken->getPasswordVersion());
+ }
}
diff --git a/application/Espo/Core/Console/Commands/SetPassword.php b/application/Espo/Core/Console/Commands/SetPassword.php
index f60603b8cb..076049870e 100644
--- a/application/Espo/Core/Console/Commands/SetPassword.php
+++ b/application/Espo/Core/Console/Commands/SetPassword.php
@@ -95,7 +95,7 @@ class SetPassword implements Command
return;
}
- $user->set('password', $this->passwordHash->hash($password));
+ $user->set(User::FIELD_PASSWORD, $this->passwordHash->hash($password));
$em->saveEntity($user);
diff --git a/application/Espo/Entities/AuthToken.php b/application/Espo/Entities/AuthToken.php
index b1d5346f56..21e62da63c 100644
--- a/application/Espo/Entities/AuthToken.php
+++ b/application/Espo/Entities/AuthToken.php
@@ -35,7 +35,10 @@ use Espo\Core\ORM\Entity as BaseEntity;
class AuthToken extends BaseEntity implements AuthTokenInterface
{
- public const ENTITY_TYPE = 'AuthToken';
+ public const string ENTITY_TYPE = 'AuthToken';
+
+ /** @since 10.0.0 */
+ public const string FIELD_PASSWORD_VERSION = 'passwordVersion';
public function getToken(): string
{
@@ -62,9 +65,19 @@ class AuthToken extends BaseEntity implements AuthTokenInterface
return $this->get('isActive');
}
- public function getHash(): ?string
+ public function getPasswordVersion(): ?int
+ {
+ return $this->get(self::FIELD_PASSWORD_VERSION);
+ }
+
+ /**
+ * @since 10.0.0
+ */
+ public function setPasswordVersion(?int $version): self
{
- return $this->get('hash');
+ $this->set(self::FIELD_PASSWORD_VERSION, $version);
+
+ return $this;
}
public function setIsActive(bool $isActive): self
@@ -88,13 +101,6 @@ class AuthToken extends BaseEntity implements AuthTokenInterface
return $this;
}
- public function setHash(?string $hash): self
- {
- $this->set('hash', $hash);
-
- return $this;
- }
-
public function setToken(string $token): self
{
$this->set('token', $token);
diff --git a/application/Espo/Entities/User.php b/application/Espo/Entities/User.php
index 799516f48e..28beb308b4 100644
--- a/application/Espo/Entities/User.php
+++ b/application/Espo/Entities/User.php
@@ -47,6 +47,10 @@ class User extends Person
public const string FIELD_USER_NAME = 'userName';
/** @since 10.0.0 */
public const string FIELD_PASSWORD = 'password';
+ /** @since 10.0.0 */
+ public const string FIELD_PASSWORD_VERSION = 'passwordVersion';
+ /** @since 10.0.0 */
+ public const string FIELD_TYPE = 'type';
public const LINK_ACCOUNTS = 'accounts';
public const LINK_CONTACT = 'contact';
@@ -67,6 +71,7 @@ class User extends Person
public const RELATIONSHIP_ENTITY_COLLABORATOR = 'EntityCollaborator';
+
public function get(string $attribute): mixed
{
if ($attribute === Field::NAME) {
@@ -346,4 +351,13 @@ class User extends Person
return false;
}
+
+ /**
+ * @since 10.0.0
+ * @internal
+ */
+ public function getPasswordVersion(): ?int
+ {
+ return $this->get(self::FIELD_PASSWORD_VERSION);
+ }
}
diff --git a/application/Espo/Hooks/User/IncrementPasswordVersion.php b/application/Espo/Hooks/User/IncrementPasswordVersion.php
new file mode 100644
index 0000000000..724088e3df
--- /dev/null
+++ b/application/Espo/Hooks/User/IncrementPasswordVersion.php
@@ -0,0 +1,59 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * 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/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Hooks\User;
+
+use Espo\Core\Hook\Hook\BeforeSave;
+use Espo\Entities\User;
+use Espo\ORM\Entity;
+use Espo\ORM\Repository\Option\SaveOptions;
+use RuntimeException;
+
+/**
+ * @implements BeforeSave<User>
+ */
+class IncrementPasswordVersion implements BeforeSave
+{
+ public function beforeSave(Entity $entity, SaveOptions $options): void
+ {
+ if (!$entity->isAttributeChanged(User::FIELD_PASSWORD)) {
+ return;
+ }
+
+ $version = $entity->get(User::FIELD_PASSWORD_VERSION) ?? 0;
+
+ if (!is_int($version)) {
+ throw new RuntimeException("Non-int passwordVersion.");
+ }
+
+ $version ++;
+
+ $entity->set(User::FIELD_PASSWORD_VERSION, $version);
+ }
+}
diff --git a/application/Espo/Resources/metadata/entityAcl/AuthToken.json b/application/Espo/Resources/metadata/entityAcl/AuthToken.json
index c8d21d726f..1fb57a1a78 100644
--- a/application/Espo/Resources/metadata/entityAcl/AuthToken.json
+++ b/application/Espo/Resources/metadata/entityAcl/AuthToken.json
@@ -24,6 +24,9 @@
"lastAccess": {
"readOnly": true
},
+ "passwordVersion": {
+ "forbidden": true
+ },
"createdAt": {
"readOnly": true
},
diff --git a/application/Espo/Resources/metadata/entityAcl/User.json b/application/Espo/Resources/metadata/entityAcl/User.json
index 66af303313..444db2dd60 100644
--- a/application/Espo/Resources/metadata/entityAcl/User.json
+++ b/application/Espo/Resources/metadata/entityAcl/User.json
@@ -16,6 +16,9 @@
"internal": true,
"nonAdminReadOnly": true
},
+ "passwordVersion": {
+ "forbidden": true
+ },
"authLogRecordId": {
"forbidden": true
},
diff --git a/application/Espo/Resources/metadata/entityDefs/AuthToken.json b/application/Espo/Resources/metadata/entityDefs/AuthToken.json
index d777cba9f3..4219d5066d 100644
--- a/application/Espo/Resources/metadata/entityDefs/AuthToken.json
+++ b/application/Espo/Resources/metadata/entityDefs/AuthToken.json
@@ -35,6 +35,13 @@
"type": "bool",
"default": true
},
+ "passwordVersion": {
+ "type": "int",
+ "default": 0,
+ "notNull": true,
+ "readOnly": true,
+ "utility": true
+ },
"lastAccess": {
"type": "datetime",
"readOnly": true,
diff --git a/application/Espo/Resources/metadata/entityDefs/User.json b/application/Espo/Resources/metadata/entityDefs/User.json
index f2347988ec..5d5d9059bc 100644
--- a/application/Espo/Resources/metadata/entityDefs/User.json
+++ b/application/Espo/Resources/metadata/entityDefs/User.json
@@ -69,6 +69,13 @@
"duplicateIgnore": true,
"fieldManagerParamList": []
},
+ "passwordVersion": {
+ "type": "int",
+ "default": 0,
+ "notNull": true,
+ "readOnly": true,
+ "utility": true
+ },
"authMethod": {
"type": "enum",
"options": ["", "ApiKey", "Hmac"],
diff --git a/application/Espo/Tools/App/AppService.php b/application/Espo/Tools/App/AppService.php
index 365ab6abf5..d010c07391 100644
--- a/application/Espo/Tools/App/AppService.php
+++ b/application/Espo/Tools/App/AppService.php
@@ -61,7 +61,7 @@ class AppService
private array $forbiddenUserAttributeList = [
'apiKey',
'authTokenId',
- 'password',
+ User::FIELD_PASSWORD,
'rolesIds',
'rolesNames',
];
diff --git a/application/Espo/Tools/App/LanguageService.php b/application/Espo/Tools/App/LanguageService.php
index 51dd64135e..8df46cb533 100644
--- a/application/Espo/Tools/App/LanguageService.php
+++ b/application/Espo/Tools/App/LanguageService.php
@@ -143,7 +143,7 @@ class LanguageService
$data['User']['fields'] = $data['User']['fields'] ?? [];
- $data['User']['fields']['password'] = $language->translate('password', 'fields', 'User');
+ $data['User']['fields'][User::FIELD_PASSWORD] = $language->translate('password', 'fields', 'User');
$data['User']['fields']['passwordConfirm'] = $language->translate('passwordConfirm', 'fields', 'User');
$data['User']['fields']['newPassword'] = $language->translate('newPassword', 'fields', 'User');
$data['User']['fields']['newPasswordConfirm'] = $language->translate('newPasswordConfirm', 'fields', 'User');
diff --git a/application/Espo/Tools/UserSecurity/Password/Service.php b/application/Espo/Tools/UserSecurity/Password/Service.php
index 4fcfa06ede..52c2bc3d91 100644
--- a/application/Espo/Tools/UserSecurity/Password/Service.php
+++ b/application/Espo/Tools/UserSecurity/Password/Service.php
@@ -44,6 +44,7 @@ use Espo\Core\Record\ServiceContainer;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\PasswordHash;
use Espo\Entities\User;
+use Espo\ORM\Defs\Params\FieldParam;
use Espo\ORM\EntityManager;
use SensitiveParameter;
@@ -208,17 +209,17 @@ class Service
}
$validLength = $this->fieldValidationManager->check(
- $user,
- 'password',
- 'maxLength',
- (object) ['password' => $password]
+ entity: $user,
+ field: User::FIELD_PASSWORD,
+ type: FieldParam::MAX_LENGTH,
+ data: (object) [User::FIELD_PASSWORD => $password],
);
if (!$validLength) {
throw new Forbidden("Password exceeds max length.");
}
- $user->set('password', $this->passwordHash->hash($password));
+ $user->set(User::FIELD_PASSWORD, $this->passwordHash->hash($password));
$this->entityManager->saveEntity($user);
}
@@ -305,14 +306,14 @@ class Service
private function savePassword(User $user, #[SensitiveParameter] string $password): void
{
- $user->set('password', $this->passwordHash->hash($password));
+ $user->set(User::FIELD_PASSWORD, $this->passwordHash->hash($password));
$this->entityManager->saveEntity($user);
}
private function savePasswordSilent(User $user, #[SensitiveParameter] string $password): void
{
- $user->set('password', $this->passwordHash->hash($password));
+ $user->set(User::FIELD_PASSWORD, $this->passwordHash->hash($password));
$this->entityManager->saveEntity($user, [SaveOption::SILENT => true]);
}
diff --git a/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php b/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php
index 1ddbd8551b..07e14d750e 100644
--- a/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php
+++ b/tests/integration/Espo/Core/Authentication/AuthToken/AuthTokenManagerTest.php
@@ -30,15 +30,17 @@
namespace tests\integration\Espo\Core\Authentication\AuthToken;
use Espo\Core\Authentication\AuthToken\Data;
+use Espo\Core\Authentication\AuthToken\Manager;
+use tests\integration\Core\BaseTestCase;
-class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
+class AuthTokenManagerTest extends BaseTestCase
{
public function testCreateWithSecret()
{
- $authTokenManager = $this->getContainer()->get('authTokenManager');
+ $authTokenManager = $this->getContainer()->getByClass(Manager::class);
$authTokenData = Data::create([
- 'hash' => 'test-hash',
+ 'passwordVersion' => 1,
'ipAddress' => 'ip-address',
'userId' => 'user-id',
'portalId' => 'portal-id',
@@ -47,7 +49,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
$authToken = $authTokenManager->create($authTokenData);
- $this->assertEquals($authTokenData->getHash(), $authToken->getHash());
+ $this->assertEquals($authTokenData->getPasswordVersion(), $authToken->getPasswordVersion());
$this->assertEquals($authTokenData->getUserId(), $authToken->getUserId());
$this->assertEquals($authTokenData->getPortalId(), $authToken->getPortalId());
@@ -61,10 +63,10 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
public function testCreateWithNoSecretNoPortal()
{
- $authTokenManager = $this->getContainer()->get('authTokenManager');
+ $authTokenManager = $this->getContainer()->getByClass(Manager::class);
$authTokenData = Data::create([
- 'hash' => 'test-hash',
+ 'passwordVersion' => 1,
'ipAddress' => 'ip-address',
'userId' => 'user-id',
'portalId' => null,
@@ -73,7 +75,7 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
$authToken = $authTokenManager->create($authTokenData);
- $this->assertEquals($authTokenData->getHash(), $authToken->getHash());
+ $this->assertEquals($authTokenData->getPasswordVersion(), $authToken->getPasswordVersion());
$this->assertEquals($authTokenData->getUserId(), $authToken->getUserId());
$this->assertEmpty($authToken->getPortalId());
@@ -84,10 +86,10 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
public function testRenew()
{
- $authTokenManager = $this->getContainer()->get('authTokenManager');
+ $authTokenManager = $this->getContainer()->getByClass(Manager::class);
$authTokenData = Data::create([
- 'hash' => 'test-hash',
+ 'passwordVersion' => 1,
'userId' => 'user-id',
]);
@@ -102,10 +104,10 @@ class AuthTokenManagerTest extends \tests\integration\Core\BaseTestCase
public function testInactivate()
{
- $authTokenManager = $this->getContainer()->get('authTokenManager');
+ $authTokenManager = $this->getContainer()->getByClass(Manager::class);
$authTokenData = Data::create([
- 'hash' => 'test-hash',
+ 'passwordVersion' => 1,
'userId' => 'user-id',
]);
diff --git a/tests/integration/Espo/Password/VersionTest.php b/tests/integration/Espo/Password/VersionTest.php
new file mode 100644
index 0000000000..fbd1b6b9dc
--- /dev/null
+++ b/tests/integration/Espo/Password/VersionTest.php
@@ -0,0 +1,52 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * 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/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace tests\integration\Espo\Password;
+
+use Espo\Entities\User;
+use tests\integration\Core\BaseTestCase;
+
+class VersionTest extends BaseTestCase
+{
+ public function testVersionIncrement(): void
+ {
+ $em = $this->getEntityManager();
+
+ $user = $em->getRDBRepositoryByClass(User::class)->getNew();
+ $user->setUserName('test');
+ $em->saveEntity($user);
+
+ $version = $user->get(User::FIELD_PASSWORD_VERSION);
+
+ $user->set(User::FIELD_PASSWORD, '1');
+ $em->saveEntity($user);
+
+ $this->assertEquals($version + 1, $user->get(User::FIELD_PASSWORD_VERSION));
+ }
+}
diff --git a/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php b/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php
index cb67c56bdd..73cf47dd0d 100644
--- a/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php
+++ b/tests/unit/Espo/Core/Authentication/AuthToken/AuthTokenDataTest.php
@@ -30,20 +30,21 @@
namespace tests\unit\Espo\Core\Authentication\AuthToken;
use Espo\Core\Authentication\AuthToken\Data;
+use PHPUnit\Framework\TestCase;
-class AuthTokenDataTest extends \PHPUnit\Framework\TestCase
+class AuthTokenDataTest extends TestCase
{
public function testCreate()
{
$authTokenData = Data::create([
- 'hash' => 'hash',
+ 'passwordVersion' => 1,
'ipAddress' => 'ip-address',
'userId' => 'user-id',
'portalId' => 'portal-id',
'createSecret' => true,
]);
- $this->assertEquals('hash', $authTokenData->getHash());
+ $this->assertEquals(1, $authTokenData->getPasswordVersion());
$this->assertEquals('ip-address', $authTokenData->getIpAddress());
$this->assertEquals('user-id', $authTokenData->getUserId());
$this->assertEquals('portal-id', $authTokenData->getPortalId());