{"Entry":{"collection":"auth","key":"scram-sha-256","name":"scram-sha-256","aliases":[],"metadata":{"aliases":[],"category":"Password authentication","content_hash":"34baf925ea247a05d1b5388da16babc95fc3f405f48652941c93fedd631c8b9d","derived_content_hash":"ce15bfbb0d9d1215d7f8f5f8fe76be162e9d3af505b1ddb1f83b4d9ccfe63899","imported_at":"2026-09-30T00:40:33.346621+08:00","name":"scram-sha-256","name_zh":"","slug":"scram-sha-256","summary":"Perform SCRAM-SHA-256 authentication to verify the user's password. See Section 20.5 for details."}},"Definition":{"Collection":"auth","Key":"scram-sha-256","SourceDatabase":"center","Version":"18","SourceTable":"authentication_method","SourceKey":"scram-sha-256","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"aliases":[],"attributes":{"configuration":"pg_hba.conf","inventory":"User-visible source authentication method","method":"scram-sha-256"},"comparison_data":{"documented_option_names":["md5","password","scram-sha-256"],"method":"scram-sha-256"},"comparison_hash":"c8064f1480a20ad588ae6df0229559199fd23ad2c0080e9d812ce710d1292dcf","description":["Perform SCRAM-SHA-256 authentication to verify the user's password. See Section 20.5 for details."],"description_zh":"认证方法 scram-sha-256。","description_zh_html":"\u003cp\u003e认证方法 scram-sha-256。\u003c/p\u003e\u003cdl\u003e\u003cdt\u003e索引访问方法\u003c/dt\u003e\u003cdd\u003e\u003ccode\u003escram-sha-256\u003c/code\u003e\u003c/dd\u003e\u003cdt\u003e配置\u003c/dt\u003e\u003cdd\u003e\u003ccode\u003epg_hba.conf\u003c/code\u003e\u003c/dd\u003e\u003c/dl\u003e\u003ch3\u003e同版本中文手册定义\u003c/h3\u003e\u003cdd\u003e\u003cp\u003e\n\u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e 方法执行 SCRAM-SHA-256 认证，其定义见 \u003ca class=\"ulink\" href=\"https://datatracker.ietf.org/doc/html/rfc7677\"\u003eRFC 7677\u003c/a\u003e。它是一种挑战-响应方案，可防止在不受信任连接上嗅探密码，并支持在服务器上以被认为安全的密码学 hash 形式存储密码。\n      \u003c/p\u003e\u003cp\u003e\n       这是当前提供的方法中最安全的一种，但是旧的客户端库不支持这种方法。\n      \u003c/p\u003e\u003c/dd\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/auth-password.html#ZH18-AUTO-CLIENT-AUTH-VARLISTENTRY-29\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","facts":[{"label":"Method","value":"scram-sha-256"},{"label":"Configuration","value":"pg_hba.conf"},{"label":"Inventory","value":"User-visible source authentication method"}],"facts_zh":[{"label":"方法","value":"scram-sha-256"},{"label":"配置","value":"pg_hba.conf"},{"label":"清单","value":"用户可见的源码认证方法"}],"manual_html":"\u003cdiv class=\"sect1\" id=\"AUTH-PASSWORD\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e20.5. Password Authentication \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThere are several password-based authentication methods. These methods operate similarly but differ in how the users' passwords are stored on the server and how the password provided by a client is sent across the connection.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e performs SCRAM-SHA-256 authentication, as described in \u003ca class=\"ulink\" href=\"https://datatracker.ietf.org/doc/html/rfc7677\"\u003eRFC 7677\u003c/a\u003e. It is a challenge-response scheme that prevents password sniffing on untrusted connections and supports storing passwords on the server in a cryptographically hashed form that is thought to be secure.\u003c/p\u003e\n\u003cp\u003eThis is the most secure of the currently provided methods, but it is not supported by older client libraries.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003emd5\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e uses a custom less secure challenge-response mechanism. It prevents password sniffing and avoids storing passwords on the server in plain text but provides no protection if an attacker manages to steal the password hash from the server. Also, the MD5 hash algorithm is nowadays no longer considered secure against determined attacks.\u003c/p\u003e\n\u003cp\u003eTo ease transition from the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e method to the newer SCRAM method, if \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e is specified as a method in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e but the user's password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead.\u003c/p\u003e\n\u003cdiv class=\"warning\"\u003e\n\u003ch3 class=\"title\"\u003eWarning\u003c/h3\u003e\n\u003cp\u003eSupport for MD5-encrypted passwords is deprecated and will be removed in a future release of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e. Refer to the text below for details about migrating to another password type.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003epassword\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e sends the password in clear-text and is therefore vulnerable to password \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003esniffing\u003c/span\u003e”\u003c/span\u003e attacks. It should always be avoided if possible. If the connection is protected by SSL encryption then \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e can be used safely, though. (Though SSL certificate authentication might be a better choice if one is depending on using SSL).\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e database passwords are separate from operating system user passwords. The password for each database user is stored in the \u003ccode class=\"literal\"\u003epg_authid\u003c/code\u003e system catalog. Passwords can be managed with the SQL commands \u003ca class=\"xref\" href=\"/docs/18/sql-createrole.html\" title=\"CREATE ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e and \u003ca class=\"xref\" href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, e.g., \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eCREATE ROLE foo WITH LOGIN PASSWORD 'secret'\u003c/code\u003e\u003c/strong\u003e, or the \u003cspan class=\"application\"\u003epsql\u003c/span\u003e command \u003ccode class=\"literal\"\u003e\\password\u003c/code\u003e. If no password has been set up for a user, the stored password is null and password authentication will always fail for that user.\u003c/p\u003e\n\u003cp\u003eThe availability of the different password-based authentication methods depends on how a user's password on the server is encrypted (or hashed, more accurately). This is controlled by the configuration parameter \u003ca class=\"xref\" href=\"/docs/18/runtime-config-connection.html#GUC-PASSWORD-ENCRYPTION\"\u003epassword_encryption\u003c/a\u003e at the time the password is set. If a password was encrypted using the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e setting, then it can be used for the authentication methods \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e (but password transmission will be in plain text in the latter case). The authentication method specification \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e will automatically switch to using the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e method in this case, as explained above, so it will also work. If a password was encrypted using the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e setting, then it can be used only for the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e authentication method specifications (again, with the password transmitted in plain text in the latter case). (Previous PostgreSQL releases supported storing the password on the server in plain text. This is no longer possible.) To check the currently stored password hashes, see the system catalog \u003ccode class=\"literal\"\u003epg_authid\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eTo upgrade an existing installation from \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e to \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e, after having ensured that all client libraries in use are new enough to support SCRAM, set \u003ccode class=\"literal\"\u003epassword_encryption = 'scram-sha-256'\u003c/code\u003e in \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e, make all users set new passwords, and change the authentication method specifications in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e to \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e","manual_path":"/docs/18/auth-password.html","related":[],"release":{"catalog_fingerprint":"65c93d6048ef30e61023a84f9680fa6a92b1c383b7eb226741170077eb078502","channel":"stable","label":"18.6","major":"18","ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"sections_zh":[],"signature":"","sources":[{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18 English manual","path":"auth-password.html","sha256":"89d87aa104ffde4d6ddb753032794cc5924db149179845d97788e0999e0971c1","url":"/docs/18/auth-password.html"},{"label":"PostgreSQL 18 English manual","path":"auth-pg-hba-conf.html","sha256":"6340d4abea2e0a3482afc31bcd1599a0fa10dc28a6f1e05d79ba831e2dd0b4c9","url":"/docs/18/auth-pg-hba-conf.html"}],"tables":[{"columns":[{"key":"name","label":"Option or term"},{"key":"description","label":"Meaning"}],"key":"method-options","rows":[{"description":"The method scram-sha-256 performs SCRAM-SHA-256 authentication, as described in RFC 7677 . It is a challenge-response scheme that prevents password sniffing on untrusted connections and supports storing passwords on the server in a cryptographically hashed form that is thought to be secure. This is the most secure of the currently provided methods, but it is not supported by older client libraries.","name":"scram-sha-256"},{"description":"The method md5 uses a custom less secure challenge-response mechanism. It prevents password sniffing and avoids storing passwords on the server in plain text but provides no protection if an attacker manages to steal the password hash from the server. Also, the MD5 hash algorithm is nowadays no longer considered secure against determined attacks. To ease transition from the md5 method to the newer SCRAM method, if md5 is specified as a method in pg_hba.conf but the user's password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead. Warning Support for MD5-encrypted passwords is deprecated and will be removed in a future release of PostgreSQL . Refer to the text below for details about migrating to another password type.","name":"md5"},{"description":"The method password sends the password in clear-text and is therefore vulnerable to password “ sniffing ” attacks. It should always be avoided if possible. If the connection is protected by SSL encryption then password can be used safely, though. (Though SSL certificate authentication might be a better choice if one is depending on using SSL).","name":"password"}],"title":"Documented method options and alternatives"}],"tables_zh":[{"columns":[{"key":"name","label":"选项或术语"},{"key":"description","label":"含义"}],"key":"method-options","rows":[{"description":"scram-sha-256 方法执行 SCRAM-SHA-256 认证，其定义见 RFC 7677 。它是一种挑战-响应方案，可防止在不受信任连接上嗅探密码，并支持在服务器上以被认为安全的密码学 hash 形式存储密码。 这是当前提供的方法中最安全的一种，但是旧的客户端库不支持这种方法。","name":"scram-sha-256"},{"description":"md5 方法使用自定义且安全性较弱的挑战响应机制。它能防止密码嗅探，避免服务器明文存储密码；但攻击者一旦窃取服务器上的密码哈希，就无法提供保护。此外，MD5 哈希算法如今已不再被认为能安全抵御有针对性的攻击。为便于从 md5 迁移到较新的 SCRAM 方法，如果 pg_hba.conf 中指定 md5，但服务器上该用户的密码采用 SCRAM 加密存储（见下文），系统会自动改用基于 SCRAM 的认证。警告：对 MD5 加密密码的支持已弃用，将在 PostgreSQL 的未来版本中移除。迁移到其他密码类型的方法参见下文。","name":"md5"},{"description":"方法 password 以明文形式发送密码，因此它容易受到密码 “ 嗅探 ” 攻击。如果可能应该尽量避免使用它。不过，如果连接被SSL加密保护着，那么可以安全地使用 password （不过如果依靠SSL，SSL证书认证可能是更好的选择）。","name":"password"}],"title":"手册中的方法选项与替代方式"}],"zh_from":{"authored_translation":"source-derived-structured-summary","body_sha256":"a460788a445ffd964f2261a6298f4da298bfcf6694b31a1fbee5a60865a2a05e","kind":"same-version-chinese-manual-with-source-derived-structured-summary","manual":{"anchor":"ZH18-AUTO-CLIENT-AUTH-VARLISTENTRY-29","build_id":107,"extraction":"exact-definition","fragment_sha256":"a79da18e7f7008eff4de8168a79b916d3f7748051dd596cde0477fdcf48e2da4","locale":"zh-Hans","page_key":"auth-password.html","source_hash":"795bbe354b786a2c87c46b378ea587634b8735effb01fed68a65957ac1599deb","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/auth-password.html#ZH18-AUTO-CLIENT-AUTH-VARLISTENTRY-29","version":"18"},"runtime_rerun":false,"source_facts_revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}},"ManualEvidence":{"manual_path":"/docs/18/auth-password.html","release":{"catalog_fingerprint":"65c93d6048ef30e61023a84f9680fa6a92b1c383b7eb226741170077eb078502","channel":"stable","label":"18.6","major":"18","ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"label":"PostgreSQL 18 English manual","path":"auth-password.html","sha256":"89d87aa104ffde4d6ddb753032794cc5924db149179845d97788e0999e0971c1","url":"/docs/18/auth-password.html"},{"label":"PostgreSQL 18 English manual","path":"auth-pg-hba-conf.html","sha256":"6340d4abea2e0a3482afc31bcd1599a0fa10dc28a6f1e05d79ba831e2dd0b4c9","url":"/docs/18/auth-pg-hba-conf.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"auth","Key":"scram-sha-256","SourceDatabase":"center","Version":"18","Locale":"en","Title":"scram-sha-256","Summary":"Perform SCRAM-SHA-256 authentication to verify the user's password. See Section 20.5 for details.","BodyHTML":"\u003cdiv id=\"AUTH-PASSWORD\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e20.5. Password Authentication \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThere are several password-based authentication methods. These methods operate similarly but differ in how the users\u0026#39; passwords are stored on the server and how the password provided by a client is sent across the connection.\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003escram-sha-256\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode\u003escram-sha-256\u003c/code\u003e performs SCRAM-SHA-256 authentication, as described in \u003ca href=\"https://datatracker.ietf.org/doc/html/rfc7677\" rel=\"nofollow\"\u003eRFC 7677\u003c/a\u003e. It is a challenge-response scheme that prevents password sniffing on untrusted connections and supports storing passwords on the server in a cryptographically hashed form that is thought to be secure.\u003c/p\u003e\n\u003cp\u003eThis is the most secure of the currently provided methods, but it is not supported by older client libraries.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003emd5\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode\u003emd5\u003c/code\u003e uses a custom less secure challenge-response mechanism. It prevents password sniffing and avoids storing passwords on the server in plain text but provides no protection if an attacker manages to steal the password hash from the server. Also, the MD5 hash algorithm is nowadays no longer considered secure against determined attacks.\u003c/p\u003e\n\u003cp\u003eTo ease transition from the \u003ccode\u003emd5\u003c/code\u003e method to the newer SCRAM method, if \u003ccode\u003emd5\u003c/code\u003e is specified as a method in \u003ccode\u003epg_hba.conf\u003c/code\u003e but the user\u0026#39;s password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead.\u003c/p\u003e\n\u003cdiv\u003e\n\u003ch3\u003eWarning\u003c/h3\u003e\n\u003cp\u003eSupport for MD5-encrypted passwords is deprecated and will be removed in a future release of \u003cspan\u003ePostgreSQL\u003c/span\u003e. Refer to the text below for details about migrating to another password type.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003epassword\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode\u003epassword\u003c/code\u003e sends the password in clear-text and is therefore vulnerable to password \u003cspan\u003e“\u003cspan\u003esniffing\u003c/span\u003e”\u003c/span\u003e attacks. It should always be avoided if possible. If the connection is protected by SSL encryption then \u003ccode\u003epassword\u003c/code\u003e can be used safely, though. (Though SSL certificate authentication might be a better choice if one is depending on using SSL).\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003cspan\u003ePostgreSQL\u003c/span\u003e database passwords are separate from operating system user passwords. The password for each database user is stored in the \u003ccode\u003epg_authid\u003c/code\u003e system catalog. Passwords can be managed with the SQL commands \u003ca href=\"/docs/18/sql-createrole.html\" title=\"CREATE ROLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e and \u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, e.g., \u003cstrong\u003e\u003ccode\u003eCREATE ROLE foo WITH LOGIN PASSWORD \u0026#39;secret\u0026#39;\u003c/code\u003e\u003c/strong\u003e, or the \u003cspan\u003epsql\u003c/span\u003e command \u003ccode\u003e\\password\u003c/code\u003e. If no password has been set up for a user, the stored password is null and password authentication will always fail for that user.\u003c/p\u003e\n\u003cp\u003eThe availability of the different password-based authentication methods depends on how a user\u0026#39;s password on the server is encrypted (or hashed, more accurately). This is controlled by the configuration parameter \u003ca href=\"/docs/18/runtime-config-connection.html#GUC-PASSWORD-ENCRYPTION\" rel=\"nofollow\"\u003epassword_encryption\u003c/a\u003e at the time the password is set. If a password was encrypted using the \u003ccode\u003escram-sha-256\u003c/code\u003e setting, then it can be used for the authentication methods \u003ccode\u003escram-sha-256\u003c/code\u003e and \u003ccode\u003epassword\u003c/code\u003e (but password transmission will be in plain text in the latter case). The authentication method specification \u003ccode\u003emd5\u003c/code\u003e will automatically switch to using the \u003ccode\u003escram-sha-256\u003c/code\u003e method in this case, as explained above, so it will also work. If a password was encrypted using the \u003ccode\u003emd5\u003c/code\u003e setting, then it can be used only for the \u003ccode\u003emd5\u003c/code\u003e and \u003ccode\u003epassword\u003c/code\u003e authentication method specifications (again, with the password transmitted in plain text in the latter case). (Previous PostgreSQL releases supported storing the password on the server in plain text. This is no longer possible.) To check the currently stored password hashes, see the system catalog \u003ccode\u003epg_authid\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eTo upgrade an existing installation from \u003ccode\u003emd5\u003c/code\u003e to \u003ccode\u003escram-sha-256\u003c/code\u003e, after having ensured that all client libraries in use are new enough to support SCRAM, set \u003ccode\u003epassword_encryption = \u0026#39;scram-sha-256\u0026#39;\u003c/code\u003e in \u003ccode\u003epostgresql.conf\u003c/code\u003e, make all users set new passwords, and change the authentication method specifications in \u003ccode\u003epg_hba.conf\u003c/code\u003e to \u003ccode\u003escram-sha-256\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"3b0977e2cc374ad7270d3c03945af9a36d268a2f285f5eab50549726917dea58","Payload":{"description":["Perform SCRAM-SHA-256 authentication to verify the user's password. See Section 20.5 for details."],"manual_html":"\u003cdiv class=\"sect1\" id=\"AUTH-PASSWORD\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e20.5. Password Authentication \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThere are several password-based authentication methods. These methods operate similarly but differ in how the users' passwords are stored on the server and how the password provided by a client is sent across the connection.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e performs SCRAM-SHA-256 authentication, as described in \u003ca class=\"ulink\" href=\"https://datatracker.ietf.org/doc/html/rfc7677\"\u003eRFC 7677\u003c/a\u003e. It is a challenge-response scheme that prevents password sniffing on untrusted connections and supports storing passwords on the server in a cryptographically hashed form that is thought to be secure.\u003c/p\u003e\n\u003cp\u003eThis is the most secure of the currently provided methods, but it is not supported by older client libraries.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003emd5\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e uses a custom less secure challenge-response mechanism. It prevents password sniffing and avoids storing passwords on the server in plain text but provides no protection if an attacker manages to steal the password hash from the server. Also, the MD5 hash algorithm is nowadays no longer considered secure against determined attacks.\u003c/p\u003e\n\u003cp\u003eTo ease transition from the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e method to the newer SCRAM method, if \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e is specified as a method in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e but the user's password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead.\u003c/p\u003e\n\u003cdiv class=\"warning\"\u003e\n\u003ch3 class=\"title\"\u003eWarning\u003c/h3\u003e\n\u003cp\u003eSupport for MD5-encrypted passwords is deprecated and will be removed in a future release of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e. Refer to the text below for details about migrating to another password type.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003epassword\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThe method \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e sends the password in clear-text and is therefore vulnerable to password \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003esniffing\u003c/span\u003e”\u003c/span\u003e attacks. It should always be avoided if possible. If the connection is protected by SSL encryption then \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e can be used safely, though. (Though SSL certificate authentication might be a better choice if one is depending on using SSL).\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e database passwords are separate from operating system user passwords. The password for each database user is stored in the \u003ccode class=\"literal\"\u003epg_authid\u003c/code\u003e system catalog. Passwords can be managed with the SQL commands \u003ca class=\"xref\" href=\"/docs/18/sql-createrole.html\" title=\"CREATE ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e and \u003ca class=\"xref\" href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, e.g., \u003cstrong class=\"userinput\"\u003e\u003ccode\u003eCREATE ROLE foo WITH LOGIN PASSWORD 'secret'\u003c/code\u003e\u003c/strong\u003e, or the \u003cspan class=\"application\"\u003epsql\u003c/span\u003e command \u003ccode class=\"literal\"\u003e\\password\u003c/code\u003e. If no password has been set up for a user, the stored password is null and password authentication will always fail for that user.\u003c/p\u003e\n\u003cp\u003eThe availability of the different password-based authentication methods depends on how a user's password on the server is encrypted (or hashed, more accurately). This is controlled by the configuration parameter \u003ca class=\"xref\" href=\"/docs/18/runtime-config-connection.html#GUC-PASSWORD-ENCRYPTION\"\u003epassword_encryption\u003c/a\u003e at the time the password is set. If a password was encrypted using the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e setting, then it can be used for the authentication methods \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e (but password transmission will be in plain text in the latter case). The authentication method specification \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e will automatically switch to using the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e method in this case, as explained above, so it will also work. If a password was encrypted using the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e setting, then it can be used only for the \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e authentication method specifications (again, with the password transmitted in plain text in the latter case). (Previous PostgreSQL releases supported storing the password on the server in plain text. This is no longer possible.) To check the currently stored password hashes, see the system catalog \u003ccode class=\"literal\"\u003epg_authid\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eTo upgrade an existing installation from \u003ccode class=\"literal\"\u003emd5\u003c/code\u003e to \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e, after having ensured that all client libraries in use are new enough to support SCRAM, set \u003ccode class=\"literal\"\u003epassword_encryption = 'scram-sha-256'\u003c/code\u003e in \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e, make all users set new passwords, and change the authentication method specifications in \u003ccode class=\"filename\"\u003epg_hba.conf\u003c/code\u003e to \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e","related":[],"sections":[],"tables":[{"columns":[{"key":"name","label":"Option or term"},{"key":"description","label":"Meaning"}],"key":"method-options","rows":[{"description":"The method scram-sha-256 performs SCRAM-SHA-256 authentication, as described in RFC 7677 . It is a challenge-response scheme that prevents password sniffing on untrusted connections and supports storing passwords on the server in a cryptographically hashed form that is thought to be secure. This is the most secure of the currently provided methods, but it is not supported by older client libraries.","name":"scram-sha-256"},{"description":"The method md5 uses a custom less secure challenge-response mechanism. It prevents password sniffing and avoids storing passwords on the server in plain text but provides no protection if an attacker manages to steal the password hash from the server. Also, the MD5 hash algorithm is nowadays no longer considered secure against determined attacks. To ease transition from the md5 method to the newer SCRAM method, if md5 is specified as a method in pg_hba.conf but the user's password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead. Warning Support for MD5-encrypted passwords is deprecated and will be removed in a future release of PostgreSQL . Refer to the text below for details about migrating to another password type.","name":"md5"},{"description":"The method password sends the password in clear-text and is therefore vulnerable to password “ sniffing ” attacks. It should always be avoided if possible. If the connection is protected by SSL encryption then password can be used safely, though. (Though SSL certificate authentication might be a better choice if one is depending on using SSL).","name":"password"}],"title":"Documented method options and alternatives"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
