i don’t see why you would want a unique combination of username AND
password. just a unique key on username should suffice. if you’ve
got one on both, that would allow two users could have the same
username with different passwords and which would satisfy the unique
restriction, and that is something you don’t want.
ie,
username unique => good
(username, password) unique => bad
ex:
mysql> create table testusers (
-> id int auto_increment,
-> username varchar(20),
-> password varchar(20),
-> primary key(id),
-> unique username_password (username, password));
so i have a unique index on the username AND password combination.
mysql> insert into testusers values (’’, ‘bob’, ‘bobpw1’);
Query OK, 1 row affected, 1 warning (0.10 sec)
mysql> insert into testusers values (’’, ‘bob’, ‘bobpw2’);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from testusers;
±—±---------±---------+
| id | username | password |
±—±---------±---------+
| 1 | bob | bobpw1 |
| 2 | bob | bobpw2 |
±—±---------±---------+
2 rows in set (0.00 sec)
now, if i just make username unique by itself:
mysql> insert into testusers values (’’, ‘bob’, ‘bobpw1’);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> insert into testusers values (’’, ‘bob’, ‘bobpw2’);
ERROR 1062 (23000): Duplicate entry ‘bob’ for key 2