The present slide contains a piece of code, that implements the authentication. The SQL string variable concatenates: SELECT statement, with the string constants taken from the text fields: and PASSWORD, of the interface. Then the SQL statement included in a variable SQL string, is sent to a database server for processing. The results of processing are saved in a variable: results.
If the results of processing are empty, then it means, that a relational table: USER, does not contain user name and password provided by a user through the interface. Then, a variable: user Has Been Authenticated, is set to false. Otherwise, if a query returns a nonempty result, then a variable: user Has Been Authenticated, is set to: true.
Hence, to pass through the authentication, we have to enter into the fields: and PASSWORD, the values, such that SELECT statement returns a nonempty result. As long as the result is nonempty, it really does not matter what SELECT statement returns from its processing on USER table.
So assume, that a malicious user intentionally types in a malicious code like the one displayed in the second paragraph of the present slide. An idea is to provide the values in the and PASSWORD fields, such that after the concatenation with the SELECT statement, a condition in the WHERE clause always evaluates to: TRUE. In such a case, SQL String variable obtains the values listed at the bottom of the present slide.
Note, that it is always true, that empty string: ' ' is always equal to an empty string: ' ' If such term is used in a disjunction on both side of a conjunction in the WHERE clause, then disjunction is always true and in the consequence a conjunction is also always true. At the end, it does not really matter what a user name and password are. SELECT statement always returns all rows from a relational table USER.