Question

I would like to hash the passwords in my database with another column of the same table. I have been trying to do this with a query, but I keep getting the same error.

This is an example query I use for testing the login. 12345678 is the password and I want to use the email address as a hash.

SELECT * FROM users WHERE
SHA1(CONCAT('12345678', `email`)) = password

When I execute this in mysql I get the following error:

#1267 - Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation '='
Was it helpful?

Solution

You can specify an explicit collation

SELECT * FROM users 
WHERE SHA1(CONCAT('12345678', `email`)) = password collate utf8_general_ci
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top