Pre-image resistance and one-way functions
A cryptographic hash function takes input of any size and produces a fixed-size output (fingerprint). Pre-image resistance means given a hash output, it is computationally infeasible to find an input that produces it. This makes hashes useful for verification: store the hash of a password, and on login, hash the submitted password and compare. Even if the hash database leaks, the attacker cannot reverse the hash to recover the password. One-way functions are a key building block of digital signatures and key derivation.
Collision resistance and data integrity
Second pre-image resistance means you cannot find a different input with the same hash as a given input. Collision resistance means you cannot find any two different inputs with the same hash, even theoretically. These enable integrity checking: hash a file, send the hash over a secure channel, and the recipient hashes the received file and compares. If the file was corrupted or tampered with, the hashes differ. Strong collision resistance is essential: SHA-1 was once standard but is now deprecated because collisions were found (not just theoretical, but computationally feasible).
Practical consequences of weak hashing
MD5 is considered broken: researchers can generate two files with identical MD5 hashes, compromising git repository integrity and digital signature verification. Certificate authorities were spoofed by creating forged certificates with the same MD5 as legitimate ones. For security-critical applications, use SHA-256 or SHA-3. For non-critical uses (checksums to detect accidental corruption, not malicious tampering), weaker hashes are acceptable. Always match the hash strength to the threat model.