Skip to content
Permalink
Browse files

EZP-25880: Make ezuser.login case in-sensitive across databases, usin…

…g case in-sensitive index (#1682)

* Revert unrelated parts of #1590 and #1561

* EZP-19123: Redo fix with lowercase index

* EZP-19123: Lowercase login in loadByLogin()

* EZP-25880: Add update sql scripts

[skip ci]
  • Loading branch information...
andrerom committed Jun 15, 2016
1 parent 3bb0e6b commit bd257edd13760869891144d0d58d86828280eca1
@@ -1973,8 +1973,8 @@ INSERT INTO `ezurlalias_ml_incr` (`id`) VALUES (35);
INSERT INTO `ezurlalias_ml_incr` (`id`) VALUES (36);
INSERT INTO `ezurlalias_ml_incr` (`id`) VALUES (37);

INSERT INTO `ezuser` (`contentobject_id`, `email`, `login`, `login_normalized`, `password_hash`, `password_hash_type`) VALUES (10,'nospam@ez.no','anonymous','anonymous','4e6f6184135228ccd45f8233d72a0363',2);
INSERT INTO `ezuser` (`contentobject_id`, `email`, `login`, `login_normalized`, `password_hash`, `password_hash_type`) VALUES (14,'nospam@ez.no','admin','admin','c78e3b0f3d9244ed8c6d1c29464bdff9',2);
INSERT INTO `ezuser` (`contentobject_id`, `email`, `login`, `password_hash`, `password_hash_type`) VALUES (10,'nospam@ez.no','anonymous','4e6f6184135228ccd45f8233d72a0363',2);
INSERT INTO `ezuser` (`contentobject_id`, `email`, `login`, `password_hash`, `password_hash_type`) VALUES (14,'nospam@ez.no','admin','c78e3b0f3d9244ed8c6d1c29464bdff9',2);

INSERT INTO `ezuser_role` (`contentobject_id`, `id`, `limit_identifier`, `limit_value`, `role_id`) VALUES (11,28,'','',1);
INSERT INTO `ezuser_role` (`contentobject_id`, `id`, `limit_identifier`, `limit_value`, `role_id`) VALUES (42,31,'','',1);
@@ -2239,11 +2239,10 @@ CREATE TABLE `ezuser` (
`contentobject_id` int(11) NOT NULL DEFAULT '0',
`email` varchar(150) NOT NULL DEFAULT '',
`login` varchar(150) NOT NULL DEFAULT '',
`login_normalized` varchar(150) NOT NULL DEFAULT '',
`password_hash` varchar(50) DEFAULT NULL,
`password_hash_type` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`contentobject_id`),
UNIQUE KEY `ezuser_login` (`login_normalized`)
UNIQUE KEY `ezuser_login` (`login`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,9 @@
SET default_storage_engine=InnoDB;
-- Set storage engine schema version number
UPDATE ezsite_data SET value='6.4.0' WHERE name='ezpublish-version';

--
-- EZP-25880: Make ezuser.login case in-sensitive across databases, using case in-sensitive index
--

ALTER TABLE ezuser DROP KEY ezuser_login, ADD UNIQUE KEY ezuser_login (login);

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,9 @@
SET default_storage_engine=InnoDB;
-- Set storage engine schema version number
UPDATE ezsite_data SET value='6.4.0' WHERE name='ezpublish-version';

--
-- EZP-25880: Make ezuser.login case in-sensitive across databases, using case in-sensitive index
--

ALTER TABLE ezuser DROP KEY ezuser_login, ADD UNIQUE KEY ezuser_login (login);
@@ -0,0 +1,9 @@
SET default_storage_engine=InnoDB;
-- Set storage engine schema version number
UPDATE ezsite_data SET value='6.4.0' WHERE name='ezpublish-version';

--
-- EZP-25880: Make ezuser.login case in-sensitive across databases, using case in-sensitive index
--

ALTER TABLE ezuser DROP COLUMN login_normalized, ADD UNIQUE KEY ezuser_login (login);

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,8 @@
-- Set storage engine schema version number
UPDATE ezsite_data SET value='6.4.0' WHERE name='ezpublish-version';

--
-- EZP-25880: Make ezuser.login case in-sensitive across databases, using case in-sensitive index
--

ALTER TABLE ezuser DROP CONSTRAINT ezuser_login, ADD CONSTRAINT ezuser_login UNIQUE KEY ((lower(login)));

This comment has been minimized.

Copy link
@wizhippo

wizhippo Jun 23, 2016

Contributor

Should we not drop the login_normalized column also?

This comment has been minimized.

Copy link
@andrerom

andrerom Jun 23, 2016

Author Member

not when coming from 5.4 (as it was added in 6.2)

This comment has been minimized.

Copy link
@wizhippo

wizhippo Jun 23, 2016

Contributor

postgresql also does not allow a lower on the constraint and "KEY" should be removed

This comment has been minimized.

Copy link
@wizhippo

wizhippo Jun 23, 2016

Contributor

"not when coming from 5.4 (as it was added in 6.2)"

Postegresql?

Alternative could be:

ALTER TABLE ezuser DROP CONSTRAINT ezuser_login;
CREATE UNIQUE INDEX ezuser_login on ezuser (lower(login));  
ALTER TABLE ezuser DROP COLUMN login_normalized;

Edit: I got it 5.4 ezpublish. Odd then that the mysql version of the same script drops it.

This comment has been minimized.

Copy link
@andrerom

andrerom Jun 23, 2016

Author Member

Then mysql is wrong here. But what Are you saying needs to be done on on postgres?

This comment has been minimized.

Copy link
@wizhippo

wizhippo Jun 23, 2016

Contributor

Yes. Postgresql doesn't support adding the case-insensitive constraint using lower. You have to use an index instead.

This comment has been minimized.

Copy link
@andrerom

andrerom Jun 27, 2016

Author Member

Back and having second look now.

mysql:

Edit: I got it 5.4 ezpublish. Odd then that the mysql version of the same script drops it.

The sql update script drops the key, and adds a new one who is UNIQUE, so should be fine afaik.

Postgres, please review: #1700

@@ -199,7 +199,7 @@ public function testUpdateUser()
$handler->update($user);
$this->assertQueryResult(
array(array(42, 'kore@example.org', 'New_lögin', 'new_lögin', 1234567890, '2')),
array(array(42, 'kore@example.org', 'New_lögin', 1234567890, '2')),
$this->handler->createSelectQuery()->select('*')->from('ezuser'),
'Expected user data to be updated.'
);
@@ -482,11 +482,10 @@ CREATE TABLE ezuser (
contentobject_id int(11) NOT NULL DEFAULT 0,
email varchar(150) NOT NULL DEFAULT '',
login varchar(150) NOT NULL DEFAULT '',
login_normalized varchar(150) NOT NULL DEFAULT '',
password_hash varchar(50) DEFAULT NULL,
password_hash_type int(11) NOT NULL DEFAULT 1,
PRIMARY KEY (contentobject_id),
UNIQUE KEY `ezuser_login` (`login_normalized`)
UNIQUE KEY `ezuser_login` (`login`)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS ezuser_role;
@@ -512,7 +512,6 @@ CREATE TABLE ezuser (
contentobject_id integer DEFAULT 0 NOT NULL,
email character varying(150) DEFAULT ''::character varying NOT NULL,
login character varying(150) DEFAULT ''::character varying NOT NULL,
login_normalized character varying(150) DEFAULT ''::character varying NOT NULL,
password_hash character varying(50),
password_hash_type integer DEFAULT 1 NOT NULL
);
@@ -730,7 +729,7 @@ CREATE INDEX ezurlalias_ml_text ON ezurlalias_ml USING btree (text, id, link);

CREATE INDEX ezurlalias_ml_text_lang ON ezurlalias_ml USING btree (text, lang_mask, parent);

CREATE UNIQUE INDEX ezuser_login ON ezuser USING btree (login_normalized);
CREATE UNIQUE INDEX ezuser_login ON ezuser USING btree ((lower(login)));

CREATE INDEX hash_key ON ezuser_accountkey USING btree (hash_key);

@@ -432,12 +432,11 @@ CREATE TABLE ezuser (
contentobject_id integer NOT NULL DEFAULT 0,
email text(150) NOT NULL,
login text(150) NOT NULL,
login_normalized text(150) NOT NULL,
password_hash text(50),
password_hash_type integer NOT NULL DEFAULT 1,
PRIMARY KEY (contentobject_id)
);
CREATE UNIQUE INDEX ezuser_login ON ezuser (login_normalized);
CREATE UNIQUE INDEX ezuser_login ON ezuser (login COLLATE NOCASE);

CREATE TABLE ezuser_role (
contentobject_id integer,
@@ -54,9 +54,6 @@ public function createUser(User $user)
)->set(
$this->handler->quoteColumn('login'),
$query->bindValue($user->login)
)->set(
$this->handler->quoteColumn('login_normalized'),
$query->bindValue(mb_strtolower($user->login, 'UTF-8'))
)->set(
$this->handler->quoteColumn('email'),
$query->bindValue($user->email)
@@ -182,7 +179,8 @@ public function loadByLogin($login)
)
)->where(
$query->expr->eq(
$this->handler->quoteColumn('login_normalized', 'ezuser'),
$this->handler->quoteColumn('login', 'ezuser'),
// Index is case in-sensitive, on some db's lowercase, so we lowercase $login
$query->bindValue(mb_strtolower($login, 'UTF-8'), null, \PDO::PARAM_STR)
)
);
@@ -245,9 +243,6 @@ public function updateUser(User $user)
->set(
$this->handler->quoteColumn('login'),
$query->bindValue($user->login)
)->set(
$this->handler->quoteColumn('login_normalized'),
$query->bindValue(mb_strtolower($user->login, 'UTF-8'))
)->set(
$this->handler->quoteColumn('email'),
$query->bindValue($user->email)
@@ -11462,15 +11462,13 @@
'contentobject_id' => '10',
'email' => 'nospam@ez.no',
'login' => 'anonymous',
'login_normalized' => 'anonymous',
'password_hash' => '4e6f6184135228ccd45f8233d72a0363',
'password_hash_type' => '2',
),
1 => array(
'contentobject_id' => '14',
'email' => 'spam@ez.no',
'login' => 'admin',
'login_normalized' => 'admin',
'password_hash' => 'c78e3b0f3d9244ed8c6d1c29464bdff9',
'password_hash_type' => '2',
),
@@ -13091,15 +13091,13 @@
'contentobject_id' => '10',
'email' => 'nospam@ez.no',
'login' => 'anonymous',
'login_normalized' => 'anonymous',
'password_hash' => '4e6f6184135228ccd45f8233d72a0363',
'password_hash_type' => '2',
),
1 => array(
'contentobject_id' => '14',
'email' => 'spam@ez.no',
'login' => 'admin',
'login_normalized' => 'admin',
'password_hash' => 'c78e3b0f3d9244ed8c6d1c29464bdff9',
'password_hash_type' => '2',
),
'contentobject_id' => '10',
'email' => 'nospam@ez.no',
'login' => 'anonymous',
'login_normalized' => 'anonymous',
'password_hash' => '4e6f6184135228ccd45f8233d72a0363',
'password_hash_type' => '2',
),
'contentobject_id' => '14',
'email' => 'kn@ez.no',
'login' => 'admin',
'login_normalized' => 'admin',
'password_hash' => 'c78e3b0f3d9244ed8c6d1c29464bdff9',
'password_hash_type' => '2',
),
'contentobject_id' => '226',
'email' => 'pa@ez.no',
'login' => 'a_member',
'login_normalized' => 'a_member',
'password_hash' => 'c78e3b0f3d9244ed8c6d1c29464bdff9',
'password_hash_type' => '2',
),

0 comments on commit bd257ed

Please sign in to comment.
You can’t perform that action at this time.