SQL question

Matt Graham mhgraham at crow202.org
Mon Mar 6 09:20:37 MST 2017


On 2017-03-05 21:27, Herminio Hernandez, Jr. wrote:
> UPDATE users SET
> password=ENCRYPT(%p,concat(_utf8'$1$',right(md5(rand()),8),_utf8'$'))
> WHERE username=%u LIMIT 1
> 
> This is using md5 for the hashing where as I am using SHA

To expand on this, the MySQL encrypt() function calls the system's 
crypt() function, which can be made to use a number of different hashes. 
A salt starting with $1$ is md5, $6$ is SHA512.

> INSERT INTO `servermail`.`virtual_users`
> (`id`, `domain_id`, `password` , `email`)
> VALUES
> ('1', '1', ENCRYPT('firstpassword', CONCAT('$6$',
> SUBSTRING(SHA(RAND()), -16))), 'email1 at example.com'),
> I want to format this query correctly.

I think this isn't quite right, because the salt has to end with a $ 
according to the man page for crypt.  I think you want CONCAT('$6$', 
SUBSTRING(SHA(RAND()), -16),'$')) but I could be wrong.

-- 
Crow202 Blog: http://crow202.org/wordpress
There is no Darkness in Eternity
But only Light too dim for us to see.


More information about the PLUG-discuss mailing list