views:

2535

answers:

5

In Sql Server 2005 what data type should be used to store passwords hashed by SHA-256 algorithm?

The data is hashed by the application and passed to the database

+1  A: 

Should produce a 32-byte value (256 bits), so binary(32) ought to work.

tvanfosson
+2  A: 

varbinary(32) or binary (32).

ConcernedOfTunbridgeWells
+1  A: 

The "Hash" attribute of the SHA256Managed class is an array of bytes, and HashSize is 256 bits, so I believe a binary(32) would be the simplest.

You could probably also put it into a varchar field using the ToBase64Transform. I'm not completely familiar with the Base64 Algorithm, but It seems like you would need probably need at least 43 characters to represent a 256 bit number in base 64. IIRC Base64 uses a couple padding characters, so I'd probably put it at varchar(50) just to be safe.

Adam N
A: 

SHA-256 has a 256 bit output

256bits = 32 Bytes

So try varbinary(32)

Eoin Campbell
+5  A: 

I prefer to convert the hash-Code to an Hex-String in this case a varchar(64) will do the trick or an varchar (66) if you like a "0x"-prefix. In this way it is much easier to compare manually or (re)set values you have to copy/paste from other places. e.g you lost your admin-PW and want to reset it via SQL...

Peter Parker