Securing Stored Passwords
Securing Data: Passwords, Cryptography, and Data Protection
Password storage and hashing
A website or application must be able to check that a person knows the password associated with an account. A naïve design stores each username together with its password in readable, plaintext form. If an attacker obtains this database, the attacker immediately learns the users’ passwords and may try them on other services. Reusing a password makes this especially dangerous because a breach of one service can lead to account takeovers elsewhere.
A safer design avoids storing the password itself. Instead, the service stores a hash of the password.
What hashing does
A hash function takes an input and produces a hash value, also called a digest. The input could be a password or another string of arbitrary length; the output is typically a fixed-length sequence that looks unrelated to the original input.
If a hash function is represented by f, and its input by x, its output can be written as f(x). For passwords, the service calculates the hash when an account is created and stores the hash alongside the username—not the original password.
A simple function that maps a password to a number based only on its first letter illustrates the idea, but it is not secure: many different inputs would produce the same result, and the output would reveal information about the input. Cryptographic hash functions are designed to produce less revealing outputs and to make it impractical to recover an input from its hash.
How hashed passwords are checked
Account creation: The user submits a username and password. The server hashes the password, stores the username and hash, and discards the plaintext password.
Login: The user submits the same username and password again. The server hashes the submitted password using the same process.
Comparison: The server compares the newly calculated hash with the stored hash. If they match, the user is authenticated.
The server does not need to recover the original password to check it. It only needs to repeat the calculation and compare the result.
A password hash is a one-way verifier, not an encrypted password. A service using password hashing correctly should not be able to retrieve and email a user’s original password.
Limits of hashing
Hashing improves security, but it does not prevent every attack. If an attacker steals a database of password hashes, the attacker can still try to discover passwords by guessing them and checking whether their hashes match.
Dictionary attack: The attacker tries likely passwords, such as common words or entries from a password list, hashes each guess, and compares the results with stolen hashes.
Brute-force attack: The attacker systematically tries possible combinations of letters, numbers, and other characters.
Precomputed attack: The attacker prepares hashes of likely passwords in advance, then compares those results with stolen hashes. A large precomputed collection of password–hash pairs is commonly called a rainbow table.
Hashing raises the cost of these attacks because the attacker must do more than compare stolen plaintext passwords. But if passwords are weak, common, or short, guesses may still succeed.
A large hash output space does not by itself make password guessing impractical. Password strength and the cost of each password-guessing trial matter too. Password-storage systems therefore use purpose-built, deliberately expensive key derivation functions so that trying many guesses requires significant computation.
Salts
If two users choose the same password and the service hashes both passwords in exactly the same way, the stored hashes will be identical. This reveals that the users share a password and can help an attacker identify likely passwords.
A salt is a value added to the password before it is hashed. The service generates a salt for each password and calculates a hash based on both the password and the salt.
Different salts make identical passwords produce different stored results.
A salt is not a secret. It is stored with the password hash so that the service can use it again at login.
During login, the service retrieves the user’s salt, combines it with the submitted password, and checks whether the resulting hash matches the stored value.
Salts frustrate precomputed tables because an attacker must recompute guesses for each salt.
Each password should have its own randomly generated salt. If two accounts happen to receive the same salt, identical passwords could still produce identical hashes, but well-designed systems use salts large enough to make collisions unlikely. Very short salts, such as two characters, are not an appropriate modern design.
Password-hashing standards and good practice
Password storage should use a well-studied, suitable one-way key derivation function, configured to make each password-guessing trial expensive. Modern password-storage methods are designed for this purpose; a general-purpose hash function is not automatically an appropriate password-storage scheme.
Standards and recommendations from organizations such as the National Institute of Standards and Technology emphasize salting and hashing memorized secrets to resist offline attacks. The goal is to make a stolen password database much less useful to an attacker.
Services should rely on established, reviewed libraries and standards rather than inventing their own cryptographic schemes. Security algorithms require careful analysis and testing; improvised implementations can contain subtle flaws.
Hash collisions and one-way functions
A cryptographic hash function accepts inputs of arbitrary length but produces outputs of fixed length. Because there are more possible inputs than outputs, collisions—different inputs with the same hash—must exist mathematically. This follows from the fact that a larger set of inputs is being mapped to a smaller, finite set of outputs.
A secure cryptographic hash function is designed to make useful collisions and password recovery computationally difficult. A hash’s fixed-length output does not identify its original input uniquely: multiple inputs can, in principle, map to the same output. For this reason, hashing is not reliably reversible.
The central distinction is:
Hashing: One-way transformation used for verification; the original input is not meant to be recovered.
Encryption: Reversible transformation used to protect information that an authorized recipient must later recover.
Password-reset warning
If a website can send a user their original password, it is likely storing the password in a recoverable form rather than using appropriate one-way password hashing. A well-designed service should instead let the user reset the password by setting a new one.
A user who encounters a service that emails the original password should avoid reusing that password elsewhere and should consider no longer using the service.
Cryptography: codes and ciphers
Cryptography is the practice and study of protecting information, including information stored on a device and information sent between people or systems. Two historical approaches are codes and ciphers.
Codes
A code maps words or phrases to other words or phrases. A codebook gives the mapping between a code word and the message it represents.
To send a message, the sender converts the plaintext into code words. The recipient uses the same codebook to recover the plaintext.
Codes can be cumbersome because users may need to look up many entries. A stolen codebook can also expose messages that were sent using it and may compromise future communications.
Ciphers
A cipher transforms information according to a repeatable procedure or algorithm. Ciphers may operate on individual letters or, in digital systems, on bits. They are more algorithmic than codebooks and can be configured with a key.
Important terminology:
Plaintext: The readable message before protection.
Ciphertext: The transformed message produced by encryption.
Encrypt or encipher: Convert plaintext into ciphertext.
Decrypt or decipher: Convert ciphertext back into plaintext.
A secure cipher does not depend on hiding the algorithm. Instead, its use is configured by a key that must be protected as required by the system.
Secret-key (symmetric) encryption
In secret-key encryption, also called symmetric-key encryption, the sender and recipient use the same secret key. The sender combines the plaintext with the key through an encryption algorithm to produce ciphertext. The recipient uses the corresponding decryption process and the same key to recover the plaintext.
The key is not normally a human-memorable password. It is generally generated by a computer and represented internally as data, such as bits.
The Caesar cipher
The Caesar cipher is a simple example of a rotational cipher. It shifts each letter of the alphabet by a fixed number of positions. With a key of one, for example, A becomes B and B becomes C; the alphabet wraps around at the end. Decryption shifts the letters back.
A key of thirteen produces the familiar ROT13 transformation. ROT13 can obscure text casually, but it is not secure encryption. A key equal to the number of letters in the alphabet leaves the letters unchanged.
The Caesar cipher is easy to break because there are only a small number of possible shifts. An attacker can try each key until the plaintext becomes readable. Modern security must use algorithms and key sizes that make such guessing infeasible.
Modern symmetric algorithms
AES and triple DES are examples of established symmetric encryption algorithms discussed in the source. With symmetric encryption, both parties must have the same key. The algorithm may be public; the key must be kept secret.
Symmetric encryption is useful for efficiently protecting data, but it creates a key-distribution problem: how can two parties who have not communicated before securely agree on a shared secret?
Public-key (asymmetric) cryptography
Public-key cryptography, also called asymmetric-key cryptography, uses a related pair of keys:
A public key can be shared openly.
A private key is kept secret by its owner.
The keys are mathematically related. In public-key encryption, someone can use the recipient’s public key to encrypt a message, but only the recipient’s corresponding private key can decrypt it. This allows people to communicate securely without first exchanging a secret key.
Public-key systems solve the initial key-sharing problem in a way symmetric encryption alone cannot. In practice, systems often use public-key techniques to establish or protect keys, then use efficient symmetric encryption for the bulk of the communication.
RSA at a high level
RSA is a widely known public-key algorithm. Its security is connected to the difficulty of factoring the product of large prime numbers.
At a simplified level:
The system selects large prime numbers p and q.
It multiplies them to obtain n=pq.
The algorithm uses n and related values to construct public and private keys.
Multiplying two large primes is straightforward for a computer, but recovering the original primes from their product is believed to be computationally difficult when the numbers are sufficiently large.
A simplified description of RSA encryption and decryption is:
Here, m represents a numeric form of the message, c the ciphertext, e a public-key value, d a private-key value, and n a shared part of the key construction. The notation (modn) means that the calculation uses the remainder after division by n.
These equations capture the basic idea, not a complete implementation. Practical RSA requires carefully designed encoding and padding procedures. Secure systems use reviewed implementations rather than applying the simplified equations directly.
Diffie–Hellman key exchange
Diffie–Hellman is a method for establishing a shared secret over a channel that an attacker may observe. It allows two parties to derive the same secret without sending that secret itself.
In a simplified version:
Alice and Bob agree publicly on a generator g and a large prime number p.
Alice chooses a private value a and calculates A=gamodp.
Bob chooses a private value b and calculates B=gbmodp.
They exchange A and B over the channel.
Alice calculates s=Bamodp, while Bob calculates s=Abmodp.
Both calculations produce the same shared secret:
An eavesdropper may see the public parameters and exchanged values, but should not be able to efficiently derive the shared secret without the private values a or b.
Diffie–Hellman establishes a shared secret; by itself, it does not prove who the participants are. Without authentication, an attacker could potentially impersonate each party to the other. Real systems combine key exchange with authentication and other protections.
Digital signatures
A digital signature provides a way to verify that a message or document was approved by the holder of a particular private key and has not been altered since it was signed. Digital signatures are not the same as handwritten signatures, and they do not by themselves make the document confidential.
Signing and verification
A simplified digital-signature process works as follows:
The signer hashes the document to produce a fixed-length digest.
The signer uses a digital-signature algorithm and their private key to create a signature based on that digest.
The signer sends the document and signature to the recipient.
The recipient hashes the received document independently.
The recipient uses the signer’s public key and the signature to verify that the signature corresponds to the document’s digest.
If verification succeeds, it supports the conclusion that the document has not changed and that the signature was made using the private key corresponding to the public key used for verification.
Modern signature algorithms perform signing and verification according to their defined procedures; describing them simply as “encrypting a hash with a private key” is a useful introductory analogy, not a complete account of every implementation.
What digital signatures provide
Digital signatures primarily support:
Integrity: Changes to the signed content cause verification to fail.
Authentication: A valid signature indicates that the signer had access to the corresponding private key.
Evidence of approval: The signature can be used to associate a document with a key holder.
They do not hide the document. Encryption is needed when confidentiality is also required.
A public key must be reliably associated with the person or organization it is claimed to represent. That association can be supported by trusted registries, certificates, or other trusted channels. If the private key is stolen, an attacker may be able to create signatures that appear valid.
Passkeys and passwordless authentication
Passkeys are a passwordless authentication approach based on public-key cryptography. They reduce the need for users to invent, memorize, and enter passwords for every account.
Registration
When a user registers a passkey for a website or application:
The user’s device may ask for a local confirmation, such as a fingerprint, face scan, or PIN.
The device generates a public–private key pair for that service.
The device sends the public key and identifying account information to the service.
The private key remains protected on the user’s device or in a securely synchronized system.
The biometric or PIN typically unlocks or authorizes use of the private key on the device; it is not itself sent to the website as the account password.
Sign-in
When the user later signs in:
The website sends a randomly generated challenge.
The device signs the challenge using the account’s private key.
The website verifies the signature using the public key stored during registration.
A valid response demonstrates that the user’s device can access the private key associated with the account. The site does not need to receive a password.
Passkeys depend on retaining access to the relevant key, either on the original device or through secure synchronization and recovery arrangements. Adoption varies across services, and recovery remains important if devices are lost.
Encryption in transit and end-to-end encryption
Encryption in transit
Encryption in transit protects data while it travels between two points, such as a user’s device and a website. HTTPS is a common way to secure a browser’s connection to a website.
An encrypted connection to a service protects the connection from many outside observers. It does not necessarily prevent the service itself from reading the data. For example, a user may have an encrypted connection to an email provider, and the recipient may also have an encrypted connection to that provider, while the provider can still technically access the messages stored on its servers.
Encryption between a user and an intermediary is not automatically encryption between the user and the final recipient.
End-to-end encryption
End-to-end encryption protects a message so that only the intended communicating endpoints can read it. Intermediary systems may carry the ciphertext but should not have the keys needed to recover the plaintext.
Whether a service provides end-to-end encryption depends on its design and implementation. Users should distinguish it from a service that encrypts only the connection between each user and the service.
Deleting files and secure deletion
A computer stores files as patterns of bits—0s and 1s—on storage devices such as hard drives, solid-state drives, and USB drives.
What ordinary deletion does
When a user moves a file to a recycle bin or trash, the file is generally not erased immediately. Emptying the bin often removes the operating system’s reference to the file and marks its storage space as available for reuse.
The underlying bits may remain until other data overwrites them. As a result, parts of a deleted file may sometimes be recoverable for a period of time. Ordinary deletion should not be assumed to securely erase sensitive information.
Secure deletion and storage limits
A traditional approach to secure deletion is to overwrite the file’s storage area with other data, such as zeros, ones, or a random pattern. The aim is to prevent recovery of the original content.
This approach is not always reliable on modern solid-state storage. Such devices may use wear-leveling and internal storage management, so an overwrite command may not reach every physical copy of a file. Their firmware may also avoid reusing storage locations that are wearing out. Secure-erasure behavior therefore depends on the device and operating system.
Encryption at rest and full-disk encryption
Encryption at rest protects data stored on a device. Full-disk encryption applies this idea to the device’s storage broadly, so that data is unreadable when the device is locked or powered off unless the appropriate key is available.
When an authorized user unlocks the device, the system makes the data usable. If the device is stolen while locked, encryption at rest can prevent someone from simply removing the storage or reading its contents.
Encryption at rest also helps when a device is retired or transferred. If its data has been encrypted with a strong key and that key is securely discarded, the old data may become inaccessible even if some physical storage remnants remain. This approach is often more dependable than trying to overwrite every location on modern solid-state storage.
Encryption at rest has limits. It does not necessarily protect data while a device is unlocked and in use, especially if malware or an unauthorized person can access the active session. Users must also protect the credentials and recovery mechanisms needed to unlock their data. Losing access to those can mean losing access to the data itself.
Ransomware
Ransomware is malicious software that encrypts data or systems and demands payment in exchange for a decryption key or restoration. Attackers may target personal devices, companies, hospitals, universities, or municipal networks.
Paying a ransom does not guarantee that the attacker will provide a working key or that the data will be restored. Ransomware illustrates how encryption can be used both for legitimate protection and for extortion. Secure backups and strong system defenses are important safeguards.
Quantum computing and cryptographic risk
Ordinary computers represent information using bits, each of which has a value of 0 or 1. Quantum computers use qubits, which can be prepared in quantum states involving superposition and, in some cases, entanglement.
A system of n qubits can represent a state involving 2n possible basis states. This does not mean that a quantum computer can simply perform every possible computation independently and read out all the answers at once. Quantum algorithms gain speed for particular problems by exploiting quantum effects, and measurement does not reveal every component of a superposition.
If sufficiently capable quantum computers become available, some widely used public-key cryptography could be threatened. In particular, a large-scale quantum computer running an appropriate algorithm could undermine the mathematical problems on which systems such as RSA and some elliptic-curve cryptography depend. Quantum techniques can also improve certain search attacks, though not by making every cryptographic attack exponentially faster.
The development of quantum computers motivates the transition to post-quantum cryptography: cryptographic methods designed to withstand known quantum attacks. Security standards and algorithms must evolve as computing capabilities change.

Ask anything
We've read this whole study set, so questions about it get the best answers.