Reputation: 11
I have a table user
with 2 rows
CREATE TABLE `user` (
`id_user` INT(9) AUTO_INCREMENT,
`login` VARCHAR(50),
`passw` VARCHAR(32),
PRIMARY KEY (`id_user`)
) CHARSET=utf8 COLLATE utf8_general_ci;
INSERT INTO `user` VALUES
(NULL, 'Admin', '123'),
(NULL, 'Nik', '456');
then i make a query:
SELECT * FROM `user` WHERE `login` = '' OR ''='' AND `passw`='' OR ''=''
the result :
1 Admin 123
2 Nik 456
So how it works? What does it mean ''=''
?
I would be grateful if you could advise literature where I can learn about something similar.
Upvotes: 0
Views: 47
Reputation: 222682
This looks like a SQL injection attempt. This:
WHERE `login` = '' OR ''='' AND `passw`='' OR ''=''
Evaluates as:
WHERE `login` = ''
OR (''='' AND `passw`='')
OR ''=''
Condition '' = ''
is always true (the empty string is equal to the empty string), so the WHERE
clause evaluates as true for every row of the table: the query returns the whole table.
Upvotes: 4