diff --git a/install/migrations/update_10.0.10_to_10.0.11/user.php b/install/migrations/update_10.0.10_to_10.0.11/user.php new file mode 100644 index 000000000000..b854f0729996 --- /dev/null +++ b/install/migrations/update_10.0.10_to_10.0.11/user.php @@ -0,0 +1,46 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var \Migration $migration + */ + +// Add user_dn_hash field +$migration->addField('glpi_users', 'user_dn_hash', 'varchar(255) GENERATED ALWAYS AS (sha2(`user_dn`,256)) VIRTUAL', [ + 'after' => 'user_dn', +]); + +// Add user_dn_hash index +$migration->addKey('glpi_users', 'user_dn_hash'); diff --git a/install/mysql/glpi-empty.sql b/install/mysql/glpi-empty.sql index 950a74074f66..15439f62ec53 100644 --- a/install/mysql/glpi-empty.sql +++ b/install/mysql/glpi-empty.sql @@ -7608,6 +7608,7 @@ CREATE TABLE `glpi_users` ( `password_forget_token` char(40) DEFAULT NULL, `password_forget_token_date` timestamp NULL DEFAULT NULL, `user_dn` text, + `user_dn_hash` varchar(255) GENERATED ALWAYS AS (sha2(`user_dn`,256)) VIRTUAL, `registration_number` varchar(255) DEFAULT NULL, `show_count_on_tabs` tinyint DEFAULT NULL, `refresh_views` int DEFAULT NULL, @@ -7684,7 +7685,8 @@ CREATE TABLE `glpi_users` ( KEY `groups_id` (`groups_id`), KEY `users_id_supervisor` (`users_id_supervisor`), KEY `auths_id` (`auths_id`), - KEY `default_requesttypes_id` (`default_requesttypes_id`) + KEY `default_requesttypes_id` (`default_requesttypes_id`), + KEY `user_dn_hash` (`user_dn_hash`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; diff --git a/src/User.php b/src/User.php index f6c9efa0ec2f..0115d82c5cea 100644 --- a/src/User.php +++ b/src/User.php @@ -558,7 +558,9 @@ public function getFromDBbySyncField($value) */ public function getFromDBbyDn($user_dn) { - return $this->getFromDBByCrit(['user_dn' => $user_dn]); + return $this->getFromDBByCrit([ + 'user_dn_hash' => hash('sha256', $user_dn) + ]); } /**