Security Guides Beginner Friendly

Web Security Fundamentals

Passwords, Hashing, and Encryption โ€” Explained Clearly

15 min read โ€ข Updated March 2026

Why Web Security Matters

Every day, millions of people's passwords, credit card numbers, and personal data are stolen in data breaches. In 2023 alone, over 3 billion records were exposed through publicly reported breaches. Many of these breaches succeed not because attackers used exotic techniques, but because of basic security mistakes โ€” weak passwords, unencrypted data, and poor hashing practices.

Understanding the fundamentals of web security doesn't require a computer science degree. The core concepts โ€” how passwords should be stored, what hashing does, and how encryption protects data in transit โ€” are accessible to anyone willing to spend 15 minutes learning them. This guide explains these concepts in plain language, with real-world examples that show why each one matters.

Whether you're a developer building applications, a system administrator managing user accounts, or simply someone who wants to understand how their data is (or isn't) being protected, this guide gives you the vocabulary and mental models to evaluate security decisions effectively.

The three pillars of data security:

  • Confidentiality โ€” Only authorized parties can read the data (encryption)
  • Integrity โ€” Data hasn't been tampered with (hashing)
  • Availability โ€” Data is accessible when needed (backups, redundancy)

Passwords 101: What Makes a Password Secure?

A secure password is one that's computationally expensive to guess. The security of a password is measured in "entropy" โ€” essentially, how many possible values an attacker would have to try before guessing correctly. Higher entropy means more guesses required, which means more time, which means better security.

What Determines Password Strength?

Password strength is determined by two factors: length and character set size. The total number of possible passwords is calculated as (character set size) raised to the power of (password length).

Password strength comparison:

6 lowercase letters โ†’ 26โถ = ~309 million combinations โ†’ cracked in milliseconds
8 mixed-case + numbers โ†’ 62โธ = ~218 billion โ†’ cracked in minutes with modern hardware
16 mixed chars + symbols โ†’ 95ยนโถ = ~4.4 ร— 10ยณยน โ†’ would take billions of years to brute-force

Why "Password123" Is Terrible

Despite having uppercase letters, lowercase letters, and numbers (which sounds diverse), "Password123" appears in virtually every password cracking dictionary. Attackers don't just try random character combinations โ€” they use pre-built lists of commonly used passwords, dictionary words, and known patterns. A dictionary attack can try billions of likely passwords per second on modern hardware.

The most secure passwords are randomly generated strings that don't form words or recognizable patterns. A 20-character random password drawn from letters, numbers, and symbols has ~10ยณโน possible values โ€” effectively impossible to crack even with future computing advances.

Password Reuse: The Silent Killer

Using the same password across multiple sites is arguably the biggest security risk most people take. When one site is breached, attackers immediately try those credentials on banking, email, and social media sites โ€” a technique called "credential stuffing." Even a very strong password provides no protection if it's used on a site that stores it poorly and gets breached.

The solution is a unique, random password for every account, stored in a password manager. You only need to remember one strong master password; the manager handles everything else.

What Is Hashing? (And Why It's Not Encryption)

Hashing and encryption are frequently confused, but they serve completely different purposes. Understanding the distinction is fundamental to understanding how passwords should be stored.

The Definition of a Hash Function

A hash function takes any input (a string of text, a file, a document) and produces a fixed-size output called a "hash" or "digest." The critical properties of a cryptographic hash function are:

  • Deterministic: The same input always produces the same output
  • One-way: You cannot recover the original input from the hash (irreversible)
  • Avalanche effect: A tiny change to the input produces a completely different hash
  • Fixed output size: SHA-256 always produces a 256-bit hash regardless of input size
  • Collision resistant: It's computationally infeasible to find two different inputs that produce the same hash

SHA-256 hash examples:

Input: "hello"

Hash: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824


Input: "Hello" (capital H)

Hash: 185f8db32921bd46d35ee2f90c07df95f7ab8ac79e2c8d4a01f54dbf1cb1b4c4

Why Passwords Are Hashed, Not Encrypted

Here's the key insight: a website doesn't need to know your actual password. It only needs to verify that what you typed matches what you originally set. This means there's no reason for a website to ever store or be able to recover your actual password.

When you create an account, the site hashes your password and stores only the hash. When you log in, the site hashes what you typed and compares it to the stored hash. If they match, you're authenticated โ€” and the site never needed to handle your actual password for more than a fraction of a second.

If a site uses encryption instead of hashing for passwords, that means they have a decryption key somewhere, which means your actual password could potentially be recovered โ€” either by the site employees, or by attackers who compromise the key. Properly hashed passwords are useless to an attacker who breaches the database; they only have one-way transformed values they can't reverse.

Hash Functions Beyond Passwords

Hash functions are used far beyond password storage. File integrity verification uses hashes to confirm a downloaded file hasn't been corrupted or tampered with โ€” compare the file's hash against the one published by the original source. Version control systems like Git use hashes to identify commits. Digital signatures use hashes to efficiently sign large documents. Content-addressed storage systems use hashes as file identifiers.

Common Hashing Algorithms: MD5, SHA-256, bcrypt

Not all hash functions are created equal. Some are designed for speed (useful for verifying file integrity), while others are intentionally slow (necessary for password hashing, to make brute-force attacks impractical).

MD5 โ€” Obsolete for Security

MD5 was widely used in the 1990s and early 2000s. Today, it's considered cryptographically broken. Researchers have demonstrated collision attacks that can find two different inputs producing the same MD5 hash. Additionally, enormous precomputed "rainbow tables" exist that can reverse MD5 hashes for common inputs in seconds. Never use MD5 for passwords or security-critical applications. MD5 is still useful for non-security purposes like fast checksum verification of files in trusted environments.

SHA-256 โ€” Strong but Fast

SHA-256 is part of the SHA-2 family standardized by NIST. It's cryptographically secure and widely used for file integrity, digital signatures, and certificate fingerprinting. However, it's too fast for password hashing โ€” modern GPU hardware can compute billions of SHA-256 hashes per second, making brute-force attacks practical for anything shorter than ~20 characters. For password hashing specifically, you want a slow function. For file verification and data integrity, SHA-256 is excellent.

bcrypt โ€” The Password Hashing Standard

bcrypt is specifically designed for password hashing. Its "work factor" (also called cost factor) is configurable โ€” higher values make the hash slower to compute, which means attackers can attempt fewer guesses per second. As hardware gets faster, you increase the work factor to keep pace. bcrypt also automatically incorporates a random "salt" โ€” unique random data added to each password before hashing โ€” which prevents rainbow table attacks and ensures two users with the same password get different stored hashes. Modern alternatives include Argon2 (the winner of the 2015 Password Hashing Competition) and scrypt.

The rule of thumb: use SHA-256 or SHA-3 for file integrity and data verification. Use bcrypt, Argon2, or scrypt for passwords.

What Is Encryption?

Unlike hashing, encryption is reversible. You encrypt data to protect it, and decrypt it when you need it back. Encryption transforms readable data (plaintext) into scrambled data (ciphertext) using a mathematical algorithm and a key. Only someone with the correct key can decrypt the ciphertext back to plaintext.

Encryption is essential any time you need to store or transmit sensitive data that must later be read โ€” private messages, credit card numbers, medical records, authentication tokens. You encrypt the data for storage or transmission, and decrypt it when you need to use it.

How HTTPS Protects You

Every time you visit a website with "https://" in the address bar, your connection is encrypted using TLS (Transport Layer Security). This means that even if someone intercepts the data packets traveling between your device and the website's server, they see only encrypted gibberish โ€” not your login credentials, not your credit card number, not the content of what you're reading.

TLS encryption is transparent โ€” it happens automatically without you doing anything. The padlock icon in your browser's address bar indicates the connection is encrypted. When you see "http://" without the S, data is transmitted in plaintext โ€” anyone on the same network (a coffee shop WiFi, for example) could potentially read it.

Key vs. algorithm:

The algorithm (AES, ChaCha20, RSA) is public knowledge โ€” the security comes entirely from keeping the key secret. A good encryption algorithm remains secure even if an attacker knows exactly which algorithm you're using; they still can't decrypt the data without the key. This principle is called Kerckhoffs's principle and is foundational to modern cryptography.

Symmetric vs. Asymmetric Encryption

There are two broad categories of encryption, and understanding the difference explains how secure communication on the internet actually works.

Symmetric Encryption

One key is used for both encryption and decryption. AES (Advanced Encryption Standard) is the most widely used symmetric algorithm today. It's fast and efficient, making it ideal for encrypting large amounts of data. The challenge: how do you securely share the key with the other party without an attacker intercepting it? This is called the "key distribution problem."

Asymmetric Encryption

Two mathematically linked keys: a public key (which anyone can have) and a private key (kept secret). Data encrypted with the public key can only be decrypted with the private key. This solves the key distribution problem: you share your public key openly, and anyone can use it to send you encrypted messages that only you can read. RSA is the classic asymmetric algorithm; modern alternatives include elliptic curve cryptography (ECC).

How TLS Uses Both

HTTPS connections use both types strategically. Asymmetric encryption is used first to securely exchange a symmetric key (solving the key distribution problem), then symmetric encryption handles the actual data transfer (because it's much faster than asymmetric). This hybrid approach gives you the security benefits of asymmetric encryption with the performance benefits of symmetric encryption.

When you connect to a secure website, your browser and the server perform a "TLS handshake" in milliseconds that establishes this symmetric session key โ€” all transparently and automatically.

Practical Security Tips for Everyone

Theory is valuable, but here's what you should actually do to protect yourself:

๐Ÿ”‘

Use a Password Manager

Applications like Bitwarden (free, open-source), 1Password, or KeePass generate and store unique, random passwords for every site. You remember one master password; the manager handles hundreds of unique, strong passwords automatically.

๐Ÿ“ฑ

Enable Two-Factor Authentication (2FA)

Even if an attacker has your password, 2FA requires them to also have physical access to your phone or authenticator app. Use app-based 2FA (Google Authenticator, Authy) rather than SMS where possible โ€” SIM-swapping attacks can compromise SMS-based 2FA.

๐Ÿ”

Check for Breaches

Visit HaveIBeenPwned.com to check if your email address appears in known data breaches. Many password managers now do this automatically. If a site you use is breached, change that password immediately โ€” and if you reused it anywhere, change it everywhere.

๐Ÿ”’

For Developers: Never Store Plain Text Passwords

Always hash passwords with bcrypt, Argon2, or scrypt before storing. Never write your own hashing scheme. Use established libraries. Always use a random salt per password. Never use MD5 or SHA-1 for passwords. Log failed login attempts and implement rate limiting.

๐Ÿ“ก

Always Use HTTPS

Never submit passwords or sensitive information on an HTTP site. Legitimate sites handling sensitive data always use HTTPS. When on public WiFi, use a VPN to encrypt your traffic, since even HTTPS has potential vulnerabilities on hostile networks.

Tools to Practice These Concepts