Skip to main content

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

Project description

pg_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.0.tar.gz (5.8 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.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pg_scram_sha256-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6759945f18d88e8695ccd3891db1e181aa04ac5cd03afdcc88e70cc9930bb275
MD5 314c28607dbc23151f63445cbdbabcd2
BLAKE2b-256 169e3b984d7444c58662139faef59b418ebe9b2ab7a9aef8dadad925ba2efbb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pg_scram_sha256-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35d66e8b3dcefaed5a0ea21b1797001b0dc254949a2a5b3f370ffcda8d12e47b
MD5 e757071533131f8aa3227e359cf2711c
BLAKE2b-256 ab7767d12ab3ea9caf8ed5d36c3eb21f8b8311f3f24ac8aaa4ba3585e299b02a

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