51

I'm setting up my database to receive hashed passwords and not accept plain text.

Would I go something like this?

create table User(
username varchar(20) not null,
password varchar(64) not null,
);
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
  • 1
    I know this was asked 12 years ago at this point, but I'd like to point out that hashed passwords using sha256 are _not_ best practice now and also weren't in 2010. You should use an algorithm suited for passwords such as bcrypt, plus use a salt, and probably use a module for that instead of rolling your own – MichielB Feb 08 '22 at 11:09

2 Answers2

95

Yes, a SHA256 is always 256 bits long, equivalent to 32 bytes, or 64 bytes in an hexadecimal string format. You can even use char(64) instead of varchar(64) since the size won't change.

Julien Lebosquain
  • 40,639
  • 8
  • 105
  • 117
8

Yes, it will always have 64 characters.

Undo
  • 25,519
  • 37
  • 106
  • 129
OdinX
  • 4,135
  • 1
  • 24
  • 33