maik
maik

Reputation: 63

mysql query to select username that are equal the password

I need a mysql query to select the rows that the username and password are the same.

example:

username: math123, password: math123

This is what i tried: SELECT * FROM users WHERE username == password;

Upvotes: 0

Views: 930

Answers (1)

blabla_bingo
blabla_bingo

Reputation: 2162

Use the keyword binary in the WHERE clause to have an exact match.(Otherwise, MySQL would treat characters case-insensitively when comparing string values)

SELECT * FROM users WHERE binary username = password;

Note, passwords are usually stored after they are encrypted. For instance, you can only view the hash value of MySQL users' password in mysql.users table. There are functions to encrypt strings at your proposal. e.g select password('your_password'); and more secure ones such as sha2('password_string',512)

Upvotes: 1

Related Questions