I'm going to run SHA256 on a password + salt, but I don't know how long to make my VARCHAR when setting up the mysql database. What is a good length?
views:
727answers:
3
+2
Q:
(PHP) When using a SHA256 hash, how long is the hash? (ie, how long should my mysql VARCHAR be?)
+2
A:
Why would you make it VARCHAR? It doesn't vary. It's always 64 characters, which can be determined by running anything into one of the online SHA-256 calculators.
ceejayoz
2010-02-10 23:01:48
is char(64) a valid mysql statement?
hatorade
2010-02-10 23:07:23
@hatorade: No it's not a statement, but it is a valid column type.
Mark Byers
2010-02-10 23:09:39
+6
A:
A sha256 is 256 bits longs -- as its name indicates.
If you are using an hexadecimal representation, each digit codes for 4 bits ; so you need 64 digits to represent 256 bits -- so, you need a varchar(64)
, or a char(64)
, as the length is always the same, not varying at all.
And the demo :
$hash = hash('sha256', 'hello, world!');
var_dump($hash);
Will give you :
$ php temp.php
string(64) "68e656b251e67e8358bef8483ab0d51c6619f3e7a1a9f0e75838d41ff368f728"
i.e. a string with 64 characters.
Pascal MARTIN
2010-02-10 23:04:22