liveBook · Manning

Hash function

As explained in Grokking Relational Database Design

A hash function is a function that maps variable-length input data to a fixed-length output value.

A hash function turns variable-length input, such as a password, into a fixed-length output called a hash. The process is one-way, so databases can verify passwords without storing them in plain text. section 7.4

Use password hashing carefully:

  • Hash passwords with a recognized algorithm such as bcrypt or SHA-512. section 7.4
  • Add a random salt before hashing to make brute-force and rainbow-table attacks harder. section 7.4
  • Store the resulting data at a size that fits its encoding. section 7.4

Password storage and login

A bcrypt result may be 40 bytes of binary data. Base64 encoding expands it to 60 characters, so the password column should use CHAR(60). During login, hash the supplied password in the same way and compare the result with the stored hash. section 7.4

How Grokking Relational Database Design covers it

How deep it goes
Defines hashing, explains salts and attack methods, and demonstrates storage and login verification.
Examples
Uses bcrypt output, Base64 encoding, CHAR(60), and a password comparison during login.
What you can do after
Apply bcrypt password hashing, size the database column, and verify login credentials by comparing hashes.
How it connects
Connects hashing with password storage, salting, authentication, brute-force attacks, and rainbow tables.

Also explained in

Compare how 16 books explain hash function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.