I've got a simple question which happened after i desired to store the effect of a SHA1 hash inside a MySQL database:
How lengthy if the VARCHAR area maintain that we keep hash's result?
I wouldn’t use
VARCHAR having a variable length but a kind having a fixed length. Just because a SHA-1 value is always 160 bit lengthy. The
VARCHAR would certainly waste one more byte for the size of the area that will continually be exactly the same.
I wouldn’t keep value the
SHA1 is coming back. Since it uses just 4 bit per character and therefore would want 160/4 = 40 figures. But when you utilize 8 bit per character, you'd just have a 160/8 = 20 character lengthy area.
A SHA1 hash is 40 chars lengthy!
Output size sha1 is 160 bits. That is 160/8 == 20 chars (if you are using 8-bit chars) or 160/16 = 10 (if you are using 16-bit chars).
Therefore the length is between 10 16-bit chars, and 40 hex numbers.
Regardless decide the format you will store, making the area a set size according to that format. This way you will not have wasted space.
You might still desire to use VARCHAR in instances where you do not always store a hash for that user (i.e. authenticating accounts/didn't remember login url). When a user has authenticated/transformed their login info they should not have the ability to make use of the hash and shouldn't have any reason to. You can produce a separate table to keep temporary hash -> user associations that may be erased however i don't believe many people bother to get this done.