pgpassword

package
v0.714.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pgpassword implements the PostgreSQL "md5" password verifier (hashcat mode 12): the value stored in pg_authid.rolpassword (pg_shadow.passwd) when a role uses md5 authentication. It is an offline credential primitive — compute the stored value for a candidate password, or verify a candidate against a value captured from a pg_authid / pg_dumpall --globals dump. It completes the database-credential pair with mysql_password (the MySQL/MariaDB sibling) and fits the credential toolkit's compute/verify pattern (nt_hash, ldap_password, md5crypt). Pure offline compute from operator-supplied strings; no network or device.

Algorithm

PostgreSQL's pg_md5_encrypt (src/common/md5_common.c) salts the password with the role name before a single MD5:

"md5" + hex( MD5( password ‖ username ) )

The stored value is the literal "md5" followed by 32 lowercase hex digits. The salt is the role name, so the same password under two different roles yields different stored values — verification therefore requires the username as well as the candidate password.

Wrap-vs-native judgement

Native. The verifier is a single crypto/md5 over password+username plus hex — there is nothing to wrap; the only third-party option would be a PostgreSQL client/driver, unwarranted for a pure hash. Consistent with internal/mysqlpw, internal/nthash, and internal/ldappw owning their crypto in-tree.

Verifiable / no confidently-wrong output

Strongest verification class — the construction is unambiguous (a single salted MD5, no rounds) and is exactly PostgreSQL's documented pg_md5_encrypt, gated against the stdlib-hashlib oracle ("md5"+md5(password+rolname)). A malformed stored value (missing "md5" prefix / wrong length / non-hex) is rejected with an error, never silently "verified". Out of scope: SCRAM-SHA-256 (the PostgreSQL 10+ default, hashcat 28600 — salted + iterated PBKDF2/HMAC, a different primitive) and the obsolete pre-7.2 plain-MD5 form.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compute

func Compute(password, username string) string

Compute returns the PostgreSQL md5 stored value for password under the given role name: "md5" + hex(MD5(password ‖ username)).

func Normalize

func Normalize(stored string) (string, error)

Normalize canonicalises a stored value to the "md5" + 32-lowercase-hex form, accepting an optional "md5" prefix and either hex case. It errors if the digest portion is not exactly 32 hex digits.

func Verify

func Verify(password, username, stored string) (bool, error)

Verify reports whether password under username produces the given stored value. The stored value may be supplied with or without the "md5" prefix and in either hex case; it is compared constant-time. A malformed value returns an error rather than false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL