Free · runs in your browser

Postgres MD5 Password Hash Generator

Postgres MD5 Password Hash Generator. Enter a username and password to instantly build the exact PostgreSQL MD5 password hash Postgres expects. Because the algorithm is one-way but weak against collisions, think twice before you generate an md5 hash for storing secrets.

Your values

Picks the hash used in the CREATE USER example. Both hashes and both ALTER USER commands are always shown.

Hashed in your browser only. Spaces and trailing characters change the hash.

The MD5 hash is salted with the role name exactly as typed, so App_User and app_user give different hashes.

Result

MD5 hash (legacy)
—
Plain password
—
SCRAM-SHA-256 hash
—
CREATE USER with the selected hash
—
Change password using SCRAM-SHA-256, PostgreSQL 10+ (SQL command)
—
Change password using SCRAM-SHA-256, PostgreSQL 10+ (console command)
—
Change password using MD5, legacy (SQL command)
—
Change password using MD5, legacy (console command)
—
  • No account, no logging
  • Open formulas explained below
  • Works offline once loaded

Need the exact string Postgres expects for an MD5-encrypted login? The Postgres MD5 Password Hash Generator takes a username and a password and returns the md5-prefixed value you can paste straight into any PostgreSQL database, so the secret you chose never has to reach the Postgres server in the clear.

Postgres MD5 Password Hash Generator: Formula and Inputs

The tool runs in your browser, so nothing you type leaves your machine, and the output is ready for any Postgres database you manage. A Postgres MD5 value is not a plain digest of the password. PostgreSQL appends the username to the password, runs MD5 over the combined text, and puts the literal letters md5 in front of the 32-character result. That makes it a cryptographic hash with a fixed Postgres recipe. Because the name is part of the input, one password gives two database users two different values, and renaming a login breaks its stored verifier. Two inputs and one output also make the hashing step easy to reproduce and verify elsewhere in Postgres. For cryptography coursework or protocol work, the sha3 hash generator gives you reference digests in your browser with utf-8 input.

Bar split into the 3-character md5 prefix and a 32-digit hexadecimal digest, making a 35-character PostgreSQL password hash
The stored value for reporting_svc: the md5 prefix plus the 128-bit MD5 digest of password and username.

How the MD5 Digest Combines Username and Plain Password

The whole calculation fits on one line:

$$\text{verifier} = \texttt{md5} + \operatorname{MD5}(\text{password} + \text{username})$$

To generate it by hand, join the plain password and the role name with no separator, take the result as 32 lowercase hexadecimal characters, then add the prefix. The finished string is always 35 characters long, which is a quick sanity check before you paste it into a PostgreSQL user definition.

Worked Example for a Create User Statement

Take a service login named report_svc with the password Tn7!quartz-48. Joined without a separator, the input is Tn7!quartz-48report_svc, and its MD5 digest is 6c8a2ae613564996fe687dee6d444432. With the prefix attached, the finished value is md56c8a2ae613564996fe687dee6d444432. Use it in place of the password in a normal statement:

CREATE USER report_svc WITH PASSWORD 'md56c8a2ae613564996fe687dee6d444432';

Postgres sees the md5 prefix followed by 32 hex characters, treats the value as already encoded, and stores it unchanged. The user can then log in with Tn7!quartz-48. The same value works in CREATE ROLE report_svc LOGIN PASSWORD '...', because a role with the LOGIN attribute is exactly what the shorter command makes. Copy the value from the result box and check that it matches the hash format above before you run anything against a live Postgres database.

Password Generator Settings for Random Password Strength

A verifier is only as good as the secret behind it, so the page can also build a random password when you do not bring one. Length beats symbol variety: NIST SP 800-63B favours long, unique secrets over forced composition rules, and a 20-character random draw is far harder to guess than an 8-character one with a symbol bolted on. Many security teams still demand a mix of character classes, so you control both settings; whatever you pick is joined with the username and hashed into the md5 value. The result box doubles as a quick password strength check, and the same logic suits any Postgres database you protect. On a legacy Drupal 7 site, the free drupal password hash generator outputs the salted, iterated value stored in users.pass, cut to 55 characters.

Password Length and Character Sets

Choose a password length from 8 to 64 and tick the character sets you need: uppercase, lowercase, digits and symbols. For a service account no person ever types, 20 or more characters across all four sets is a sensible starting point. Complexity rules differ between organisations, so match the policy your database administrators publish. The output stays 35 characters whatever the length, because only the digest is prefixed. Skip symbols that a connection string or shell treats specially if the credential will live in a URL.

Setting the Password with ALTER USER

To change an existing login, run ALTER USER report_svc PASSWORD 'md5...' with the generated value. ALTER USER is an alias of ALTER ROLE, so either form works, and the new verifier replaces the old one immediately. Open sessions stay connected, and a reload is needed only when you edit authentication settings, not when you change a password. If an administrator has to rehash dozens of logins, script the statements and review them before running them against production Postgres.

What a PostgreSQL Password Generator Randomizes

A trustworthy generator draws from a cryptographically secure random source, guarantees at least one character from every selected set and never repeats an earlier value. If a credential is compromised, replace it with a brand-new draw rather than a tweak of the old one. That fresh draw is what gets joined with the username before the MD5 step, so a new secret always yields a new value, which is one of the Postgres best practices for service accounts.

Pre-Encoded Hash: Keeping Plaintext Out of Logs

Running ALTER USER ... PASSWORD 'secret' sends the plaintext password to the PostgreSQL server, where statement logs, shell history files and monitoring tools can capture it. A pre-encoded hash avoids that exposure: the conversion happens before the statement is sent, so only the verifier is recorded. Treat the verifier as sensitive anyway, because with MD5 authentication the stored value is effectively the password, and anyone holding it can log in. Pair it with SSL or TLS on the connection, and review the logging settings so the original secret never appears elsewhere in your Postgres security setup.

Backups, pg_dumpall and Hashes in globals.sql

Every backup copies verifiers too. The command pg_dumpall --globals-only writes each role and its stored value into a file such as globals.sql, so an old backup can keep MD5 values alive long after a migration. Restore that file into a fresh Postgres database on a current release and you will see a warning for each MD5 value it carries. Keep the backup encrypted, and handle the application credentials inside it like any other secret. The PostgreSQL documentation lists the exact options.

Where pg_shadow and pg_authid Store the Verifier

Postgres keeps each verifier in the pg_authid catalog, and a view over it exposes the value to superusers. Run SELECT usename, passwd FROM pg_shadow to see which database users still carry MD5: that value begins with md5, while a SCRAM-SHA-256 value begins with SCRAM-SHA-256$ and holds a salt, an iteration count, a stored key and a server key.

Rotating a Postgres MD5 Verifier with the Hash Generator

Last quarter I had to rotate the credential for billing_app, a login that a legacy invoicing job still uses against an old Postgres 13 database. The job's driver only speaks MD5 authentication, so a SCRAM value is not an option yet, and the rotation ticket forbids putting the new secret in a statement the server will log.

I generate Vk9#harbor-215 as the new password, enter billing_app as the username and press generate. The tool joins Vk9#harbor-215billing_app, hashes it and returns md5ea4f09a2eba4bc67d018af3f7fc8b8f8: 35 characters, so the length check passes. I paste it into ALTER USER billing_app PASSWORD 'md5ea4f...';, then confirm the pg_shadow row for that login holds the same string. Cross-checking against a second method matters, so I also recompute the digest with Python's hashlib and get an identical result.

Rotating a Postgres MD5 Verifier with the Hash Generator
Username enteredResulting value
billing_appmd5ea4f09a2eba4bc67d018af3f7fc8b8f8
billing_apimd5773cb1271c05c512b5d5af62c9bf63e4
Billing_appmd591e5dc8ccc540991cee0017b79a243b7

The sensitivity rerun is the part worth remembering: changing one letter of the username, or its case, produces a completely different value. The number to watch is the username, because a typo there yields a clean-looking 35-character string that simply never matches at login. That is also the edge case where this method should not be trusted alone: if the role is later renamed, the stored value goes stale and the login fails until you generate a new one.

My judgement call is to treat this as a bridge. Once the job's driver is upgraded, I will set password_encryption to SCRAM, reset billing_app once more, and keep the MD5 value out of every backup.

Why the MD5 Hash Is Legacy and Deprecated in PostgreSQL

MD5 was never designed to protect passwords, and the project now flags MD5 password support for removal. A login set with an MD5 value triggers a warning on recent Postgres releases, and a future Postgres release will drop the option. The md5 hash remains useful for testing and for compatibility with old clients, but new Postgres deployments should treat it as a bridge, not a destination. You can silence the notice with the md5_password_warnings parameter, yet fixing the cause is the better configuration choice for every database.

MD5 Authentication Versus SCRAM-SHA-256

SCRAM-SHA-256 arrived in PostgreSQL 10 and became the standard for new passwords in version 14. PostgreSQL 18 then began warning about the older scheme. The authentication method changes how the client proves it knows the password, not just how the verifier is stored, and encryption of the exchange improves with it.

Timeline of PostgreSQL versions 7.2, 10, 14 and 18 showing md5 introduced, SCRAM-SHA-256 added, made the default, and md5 deprecated
PostgreSQL password encryption milestones by server version.
MD5 Authentication Versus SCRAM-SHA-256
PropertyMD5SCRAM-SHA-256
SaltName onlyRandom per password
IterationsA single pass4096 by default
Stored valueActs as the passwordStored key and server key
StatusDeprecatedDefault since release 14

SCRAM computes HMAC-SHA-256 proofs, so a stolen verifier cannot be replayed to log in the way an MD5 value can. That difference is the main reason Postgres teams migrate, and it is the answer to the common question of whether MD5 is still acceptable inside a PostgreSQL database.

Moving Users with password_encryption and pg_hba.conf

Setting password_encryption = 'scram-sha-256' changes only future passwords; every stored value stays MD5 until it is set again. Start by listing affected roles with the pg_shadow query above, then change the password encryption setting, reset each password, and only then switch the matching lines in pg_hba.conf from md5 to scram-sha-256 and reload. Doing the file first locks those users out. A SCRAM verifier is derived from the plaintext, so an MD5 value cannot be converted; every secret must be entered again. Test one application login on a single Postgres server, then repeat across the others, and let people reset their own logins where you can.

Password Expiration and Policy Checks

PostgreSQL never expires a password by itself. Set an end date with ALTER ROLE report_svc VALID UNTIL '2027-01-31', and plan the replacement before that day, because logins fail once it passes. The passwordcheck module can enforce a minimum length on submitted passwords, but it cannot inspect a pre-encoded value, which is one more reason to generate strong secrets before you hash them for any Postgres database.

Frequently Asked Questions

Why does the hash depend on the username too?
PostgreSQL includes the role (user) name in the hash input specifically so the same password produces a different stored hash for every different user -- this means two users who happen to choose the same password don't end up with identical hash values in pg_authid, which would otherwise leak that information.
Is this still used by modern PostgreSQL?
It's still supported for backward compatibility, but PostgreSQL 10+ recommends scram-sha-256 authentication instead, which is a proper salted, iterated, standards-based password verifier (RFC 5802) rather than a single unsalted-beyond-username MD5 pass. New setups should prefer scram-sha-256.
Is this hash format secure?
Not by modern standards -- MD5 is a fast hash, and using the username as the only "salt" is far weaker than a proper random salt, since usernames are often known or guessable. This tool exists for compatibility with existing PostgreSQL md5-auth setups, not as a security recommendation.
Where would I use this generated hash?
In PostgreSQL's pg_authid system catalog (via ALTER ROLE ... PASSWORD, when the server's password_encryption setting is md5) or when manually constructing an entry for a tool that needs to match PostgreSQL's legacy md5 authentication format directly.
Is my password sent anywhere?
No. The hash is computed entirely in your browser -- nothing is transmitted to a server or stored.

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the password generators, strength checkers, hash tools and security calculators on PasswordHive.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Each tool's output is checked against official test vectors or a reference implementation, and every strength and crack-time figure against the formula it uses, before it goes live.
  • Published Updated