Why Servers Can’t Know Your Original Password: Understanding Hashing and Salting
Password reset security relies on the server storing only salted hash values, not the original passwords; this article explains why plain‑text storage is unsafe, outlines hash algorithm types, demonstrates MD5’s shortcomings, and provides Java code for generating SHA‑256 + salt hashes.
When resetting a password, the server never stores the original password in plain text. Storing raw passwords is a severe security risk because anyone with database access could read them directly. Instead, servers store a cryptographic hash of the password combined with a random salt.
Hash Functions and Their Role
A hash function (also called a digest algorithm) transforms data of any length into a fixed‑length, unique identifier called a hash value. Cryptographic hash algorithms such as SHA‑2, SHA‑3, SM3, BLAKE2, and SipHash provide strong data integrity and resistance to tampering, though they may be slower. Non‑cryptographic hashes like CRC32 or MurMurHash3 are faster but vulnerable to attacks and should not be used for password storage.
Specialized "slow" hash algorithms (e.g., bcrypt, Argon2) are designed to be computationally intensive, making brute‑force attacks impractical.
Why MD5+Salt Is No Longer Recommended
Although many legacy systems use MD5 combined with a salt, MD5 suffers from weak collision resistance and is considered insecure. Modern applications should use stronger algorithms such as SHA‑256 with a salt, or better yet, a dedicated password‑hashing function like bcrypt.
Java Example: SHA‑256 with Salt
String password = "123456";
String salt = "1abd1c";
// Create SHA-256 digest object
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update((password + salt).getBytes());
// Compute hash
byte[] result = messageDigest.digest();
// Convert hash to hex string
String hexString = new HexBinaryAdapter().marshal(result);
System.out.println("Original String: " + password);
System.out.println("SHA-256 Hash: " + hexString.toLowerCase());Running the code produces output similar to:
Original String: 123456
SHA-256 Hash: 424026bb6e21ba5cda976caed81d15a3be7b1b2accabb79878758289df98cbecThe stored value in the database is the salted hash (the long hexadecimal string). When a user logs in, the server retrieves the same salt, recomputes the hash with the supplied password, and compares it to the stored hash. A match confirms the password is correct.
Key Takeaway
Hash functions are one‑way: you cannot derive the original password from its hash. Consequently, the server never knows the plain password, eliminating the risk of exposing it even if the database is compromised.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
