When a user enters a user name and password, a SQL query is created and executed to search on the database to verify them. However, the password is not stored as clear text on the database. They are encrypted with MD5 algorithm. The above query searches in the users table where name is harry and password is 5f4dcc3b5aa765d61d8327deb882cf99, which is the MD5 encrypted value of password. If matching entries are found, the user is authenticated.
In order to bypass this security mechanism, SQL code has to be injected on to the input fields. The code has to be injected in such a way that the SQL statement should generate a valid result upon execution. If the executed SQL query has errors in the syntax, it won't fetch a valid result. So filling in random SQL commands and submitting the form will not always result in successful authentication.
|SELECT * FROM users WHERE name='harry' AND password='5f4dcc3b5aa765d61d8327deb882cf99'
|' or '1'='1'#
|SELECT * FROM users WHERE name='' OR '1'='1'#' and password='6f1ed002ab5595859014ebf0951522d9'