Skip to main content

Generate and verify PostgreSQL-compatible SCRAM-SHA-256 password verifiers.

Project description

scram-sha256

Generate and verify PostgreSQL-compatible SCRAM-SHA-256 password verifiers in exactly the same format that PostgreSQL stores inside pg_authid and that PgBouncer expects inside userlist.txt.

The tool uses Python’s built-in hashlib, hmac, and pbkdf2_hmac and does not depend on OpenSSL. All cryptographic operations strictly follow RFC7677 and PostgreSQL's src/common/scram-common.c logic.

Usage

Generate SCRAM verifier

scram-sha256 mypassword

Example output:

SCRAM-SHA-256$4096:jJtPFbKh8Kbl0JUdhJLiRg==$rLZuvwE5U7S05GbFizTJt8vlTblsBF0o9g1wxI6O8IU=:Bg4xIDb0tsYY6MZU1eQDp6ccq4ImjgJ63NMI0rKq/Zs=

With custom salt (HEX):

scram-sha256 -s 00112233445566778899AABBCCDDEEFF mypassword

With custom salt (BASE64):

scram-sha256 -s ABBCEEV1sZRbI9twee59Ww== mypassword

With custiom iteration count

scram-sha256 -i 8192 mypassword

Verify password

scram-sha256 mypassword "SCRAM-SHA-256$4096:..."

Using with PostgreSQL

ALTER ROLE testuser PASSWORD 'SCRAM-SHA-256$4096:...';

Using with PgBouncer

Inside userlist.txt:

"username" "SCRAM-SHA-256$4096:..."

API Reference

from scram_sha256 import scram_sha256, verify_scram_sha256

v = scram_sha256(b"mypassword", iterations=4096, salt=None)
verify_scram_sha256("mypassword", v)  # True
verify_scram_sha256("badpassword", v)  # False

Notes

  • Salt must be 16 bytes, same as PostgreSQL.
  • Iteration count must be at least 4096 (default), per PostgreSQL defaults.
  • The tool uses hmac.compare_digest() for constant-time comparison.
  • No external C or OpenSSL dependencies, so safe in minimal containers.

License

MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg_scram_sha256-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pg_scram_sha256-1.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pg_scram_sha256-1.0.1.tar.gz.

File metadata

  • Download URL: pg_scram_sha256-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for pg_scram_sha256-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e0c4025f5222779458b718618413444833feafbeaf5dd1a9d2ecc8aa95b3aa19
MD5 3eacdf19c6e47b7362b6dbc1493c788d
BLAKE2b-256 5f7fc31dc72666fccd1dc33cb3b5cab436fda7aa9f46dc3b28d2eddb48999f1c

See more details on using hashes here.

File details

Details for the file pg_scram_sha256-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pg_scram_sha256-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00ca87456a0f03b9229da0b2ce5555587b5c6409553e0413a5a9ef24e4f94b67
MD5 a00da44e34014ac1feddd65ad722ad36
BLAKE2b-256 481f8e6b892c50dd7eda42863dede7738394ad7b90c580ac3833245d9dba53a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page