Home > Software engineering >  mysql query to select username that are equal the password
mysql query to select username that are equal the password

Time:05-31

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;

CodePudding user response:

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)

  • Related