0

I've seen there are quite a lot of questions about "Truncated incorrect INTEGER value", and I've been checking all of them, probably is my lack of MySql knowledge, but I can not find the way to apply any of the solutions to my problem, so please, some help...

I'm creating an email user in this way:

insert into users (id, name, maildir, crypt) values
('[email protected]', 'postbox_yourdomain_com',
 'yourdomain.com/postbox/',
 encrypt('loginpwd', CONCAT('$5$', MD5(RAND()))) 
);

ERROR 1305 (42000): FUNCTION yourdomain.encrypt does not exist

I have found that ENCRIPT() function is deprecated so I've changed into SHA2:

insert into users (id, name, maildir, crypt) values
('[email protected]', 'postbox_yourdomain_com',
 'yourdomain.com/postbox/',
 SHA2('loginpwd', CONCAT('$5$', MD5(RAND()))) 
);

But then I get:

ERROR 1292 (22007): Truncated incorrect INTEGER value: '$5$de4fc1ag9ae0fa4d5b7983fa9fa61458'

I have looked for the SHA2() syntax and I have unsuccessfully tried some variations... so, what would be the appropriate syntax to achieve the user creation?

1 Answer 1

1

The second parameter of the SHA2-function specifies the length of the generated hash in bits, e. g. SHA2('some password', 256) returns a 256-Bit SHA-2 hash-value. Have a look at the documentation.

6
  • Yes, I've seen it at the documentation, but, is it no possible to indicate the length by means of a function like CONCAT('$5$', MD5(RAND())) ? Aug 15, 2022 at 12:32
  • 1
    You can generate strings as you like, e. g. CONCAT('$5$', SHA2('my password', 256)). But I assume you want to generate a string that is compatible with crypt, which is not just a specific format but also based on an algorithm which is described here. This is not just a simple SHA2-hash concatenated with some salt and prefixed by $5$ but a key derivation function, too.
    – Mihe
    Aug 15, 2022 at 13:33
  • Thanks, as I don't really understand yet how this works, I have just followed your first suggestion: SHA2('some password', 512) I will read with attention the documentation you send me now, and if I can come up with a solution I'll post it here, thanks again. Aug 15, 2022 at 13:39
  • Thanks, I could create the user adding the password the way you suggested, but for some reason the password is not accepted when trying to log in on the mail server... thanks anyway!! Aug 15, 2022 at 17:12
  • Usually, there's some client software that adds user records to the database and hashes the password. Even the old ENCRYPT() function of MySQL didn't hash the password on its own but called a system function named crypt(). If you really need to hash passwords from inside MySQL it shouldn't be too hard to add a loadable function that calls crypt().
    – Mihe
    Aug 16, 2022 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.