Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

50%
+0 −0
Q&A Should a salt be stored in the same database as the hash?

With bcrypt, the salt is stored in the same string as the hash. This is done so that you have everything you need to get that hash identifier if you know the password.[1] Wikipedia breaks down the ...

posted 3mo ago by Michael‭

Answer
#1: Initial revision by user avatar Michael‭ · 2024-01-26T15:15:11Z (3 months ago)
With **bcrypt,** the salt is stored **in the same _string_** as the hash. This is done so that you have everything you need to get that hash identifier if you know the password.[^pepper] Wikipedia [breaks down the format][wiki]:

> ## Description
> The input to the bcrypt function is the password string (up to 72 bytes), a numeric cost, and a 16-byte (128-bit) salt value. The salt is typically a random value. The bcrypt function uses these inputs to compute a 24-byte (192-bit) hash. The final output of the bcrypt function is a string of the form:
>
> ```none
> $2<a/b/x/y>$[cost]$[22 character salt][31 character hash]
> ```
>
> For example, with input password `abc123xyz`, cost `12`, and a random salt, the output of bcrypt is the string
>
> ```none
> $2a$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW
> \__/\_/\____________________/\_____________________________/
> Alg Cost      Salt                        Hash
> ```
>
> Where:
> 
> - `$2a$`: The hash algorithm identifier (bcrypt)
> - `12`: Input cost (2<sup>12</sup> i.e. 4096 rounds)
> - `R9h/cIPz0gi.URNNX3kh2O`: A base-64 encoding of the input salt
> - `PST9/PgBkqquzi.Ss7KIUgO2t0jWMUW`: A base-64 encoding of the first 23 bytes of the computed 24 byte hash
>
> The base-64 encoding in bcrypt uses the table `./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`, which differs from [RFC 4648][] Base64 encoding.

[^pepper]: Or password + pepper, if you do that.

[wiki]: https://en.wikipedia.org/wiki/Bcrypt#Description
[rfc 4648]: https://datatracker.ietf.org/doc/html/rfc4648