liveBook · Manning

Hash function

As explained in ASP.NET Core in Action, 3e

A hash is a deterministic compact value computed from data such that modifying the data normally changes the resulting value.

A hash function deterministically converts data into a compact value. Changing the data normally changes the value, making hashes useful for detecting modified files and protecting stored passwords. section 18.4 section 29.4.4

Common applications include:

  • Cache busting: ASP.NET Core can hash a referenced file and append the result as a query string. Unchanged files keep the same URL and browser cache; modified files receive a new URL. section 18.4
  • Password protection: store cryptographic hashes rather than passwords directly, using an expensive algorithm such as BCrypt or PBKDF2. section 29.4.4

Versioning a script automatically

Add asp-append-version="true" to a script, image, or link element. The generated URL includes a content-based query string such as ?v=EWaMeWsJBYWmL2g_KkgXZQ5nPe; editing the file changes that value and prompts browsers to request the updated resource. section 18.4

<script src="~/js/site.js" asp-append-version="true"></script>

Shows the concise Tag Helper syntax for adding a content hash to a script URL. section 18.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains content-based cache busting and password-storage guidance, but stops short of hash algorithm internals.
Examples
Demonstrates asp-append-version on a script and contrasts unchanged versus modified file query strings.
What you can do after
Apply it via ASP.NET Core Tag Helpers for automatic asset versioning and choose expensive password-hashing algorithms for stored credentials.
How it connects
Connects hashing with cache busting, Tag Helpers, browser caching, password security, BCrypt, PBKDF2, and ASP.NET Core Identity.

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 ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.