I was sending an encrypted password (in md5) to a sql database. Accidentally, i sent an md5 encryption to an integer column. The password I entered was “test” and in my database it showed up as “5” then I did a password of “qwertyqwerty” and it showed up as “2147483647” Out of curiosity, can anyone explain to me what’s going on with this? Why are the int values so much different?
Share
MD5 does not encrypt a password, it hashes it.
A hash is a one-way function that takes a given input and creates a predictable output (that is, a given input will always have the same output), ideally such that even very similar inputs will yield vastly different outputs.
MD5 hashes are 128 bits. If you try to write those 128 bits into a 32 bit SQL column, some truncation will certainly happen.
Without understanding the specific code you used to generate the MD5, convert it to an integer, and then write it to SQL, it’s not possible to understand why in one case you got a small number, and in another you got the maximum value for a signed int. If you wish to post the code, I’m glad to comment on it.