[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eAlloyDB Omni allows you to enhance security by setting password policies for users authenticating with the built-in password method.\u003c/p\u003e\n"],["\u003cp\u003ePassword policies are set by updating GUC password parameters in the \u003ccode\u003epostgresql.conf\u003c/code\u003e file, and these policies only affect passwords created or changed after the policy is set.\u003c/p\u003e\n"],["\u003cp\u003ePassword complexity can be enforced by ensuring passwords meet requirements for lowercase, uppercase, numeric, and non-alphanumeric characters, and have a minimum length, all configured via password policy flags.\u003c/p\u003e\n"],["\u003cp\u003ePassword expiration can be enforced, including setting a password's validity period and configuring notifications for users before their passwords expire, which can be managed through specific flags.\u003c/p\u003e\n"],["\u003cp\u003eYou can prevent the use of usernames within passwords by enabling a specific policy, which will reject any password attempt that includes the username as a substring.\u003c/p\u003e\n"]]],[],null,["# Manage built-in authentication using password policies\n\nSelect a documentation version: Current (16.8.0)keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/manage-password-policy)\n- [16.8.0](/alloydb/omni/16.8.0/docs/manage-password-policy)\n- [16.3.0](/alloydb/omni/16.3.0/docs/manage-password-policy)\n- [15.12.0](/alloydb/omni/15.12.0/docs/manage-password-policy)\n- [15.7.1](/alloydb/omni/15.7.1/docs/manage-password-policy)\n- [15.7.0](/alloydb/omni/15.7.0/docs/manage-password-policy)\n- [15.5.5](/alloydb/omni/15.5.5/docs/manage-password-policy)\n\n\u003cbr /\u003e\n\nThis page describes how you can set and manage password policies for AlloyDB Omni.\n\n\u003cbr /\u003e\n\nAbout password policies\n-----------------------\n\nIf your application's database users authenticate with\nAlloyDB Omni using the built-in, password-based method,\nthen you can make authentication more secure by enforcing strong passwords. You\ncan define and enable password enforcement by\n[setting an AlloyDB Omni password policy](#set-password-policy).\n\n### Limitations of password policies\n\nAlloyDB Omni password policies have the following limitations:\n\n- Password policies apply to passwords created only after you set the policies.\n Existing user passwords aren't affected by a change in password policy.\n\n- Password policies apply to passwords entered only as plain text. Password\n policies don't apply to passwords entered as encrypted strings.\n\nSet an AlloyDB Omni password policy\n-----------------------------------\n\nYou set a password policy by updating Grand Unified Configuration (GUC) password\nparameters in your `postgresql.conf` configuration file. To learn how to set a\nGUC parameter, see\n[Configure AlloyDB Omni database flags](/alloydb/omni/current/docs/configure-database-flags).\n\nA password policy for AlloyDB Omni can include the following\noptions:\n\n- **Disallow username**: prevent the username from being used in the password.\n\n- **Password complexity**: check if the password contains the allowed number of\n lowercase, uppercase, numeric, and non-alphanumeric characters. Also check if\n the password length is valid.\n\n- **Password expiry**: make sure that passwords are rotated periodically.\n\nFor a list of the password policy flags that AlloyDB Omni\nsupports, see\n[Password policy flags](/alloydb/omni/current/docs/reference/password-policy-flags).\n\n### Preload the password validation library\n\nFor password a policy to take effect in AlloyDB Omni, the\n`alloydb_password_validation` library must be loaded. To load this library,\ndo the following:\n\n1. Locate the `postgresql.conf` configuration file for your installation of\n AlloyDB Omni and open it in a text editor.\n\n2. Locate the `shared_preload_libraries` line and check if it includes\n `alloydb_password_validation`. If it doesn't, then you need to add it. When\n finished, your `shared_preload_libraries` line looks similar to the\n following:\n\n shared_preload_libraries='google_columnar_engine,google_job_scheduler,google_storage,alloydb_password_validation'\n\n### Enforce password complexity\n\nTo enforce a password-complexity policy, do the following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n [`password.enforce_complexity`](/alloydb/omni/current/docs/reference/password-policy-flags#enforce_complexity)\n flag to `ON`.\n\n3. Use\n [password policy flags](/alloydb/omni/current/docs/reference/password-policy-flags) to\n define your password policy.\n\nFor example, to enforce a password policy that states a password must contain at\nleast one uppercase letter, one number, and be at least 10 characters long, you\nset the following in your `postgresql.conf` file:\n\n- `password.enforce_complexity = ON`\n- `password.min_uppercase_letters = 1`\n- `password.min_numerical_chars = 1`\n- `password.min_pass_length = 10`\n\nAfter these flags are set, an attempt to set a database user password that\ndoesn't comply with this password policy fails. For example, with this policy\nset, the following `psql` client command fails because the password `foo` is\nless than 10 characters and doesn't contain a number or an upper case character. \n\n CREATE USER \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eUSERNAME\u003c/span\u003e\u003c/var\u003e WITH PASSWORD foo;\n\n### Enforce password expiration\n\nTo enforce the password expiration policy, do the following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n [`password.enforce_expiration`](/alloydb/omni/current/docs/reference/password-policy-flags#enforce_expiration)\n flag to `ON`.\n\n3. Set the\n [`password.expiration_in_days`](/alloydb/omni/current/docs/reference/password-policy-flags#expiration_in_days)\n flag to the number of days after a password is set that it expires.\n\n4. Set the\n [`password.notify_expiration_in_days`](/alloydb/omni/current/docs/reference/password-policy-flags#notify_expiration_in_days)\n flag to the number of days before a password expires that a user starts\n receiving password expiration notifications.\n\nFor example, to enforce a password policy that states passwords expire after 30\ndays and that users are notified 15 days before their password expires, you must\nset the following in your `postgresql.conf` file:\n\n- `password.enforce_expiration = ON`\n- `password.expiration_in_days = 30`\n- `password.notify_expiration_in_days = 15`\n\nIf the password of a user expires, that user can't connect to\nAlloyDB Omni. To reset the password of a user, do the following:\n\n1. Connect to AlloyDB Omni using `psql`. For example, if you\n installed AlloyDB Omni using Docker, run the following\n command:\n\n docker exec -it \u003cvar translate=\"no\"\u003eCONTAINER-NAME\u003c/var\u003e psql -h localhost -U postgres\n\n2. At the `postgres=#` prompt, run the following command:\n\n ALTER USER \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e WITH '\u003cvar translate=\"no\"\u003eNEW-PASSWORD\u003c/var\u003e';\n\nFor more information about changing a user's password, see\n[`ALTER ROLE`](https://www.postgresql.org/docs/current/sql-alterrole.html) in\nPostgreSQL documentation.\n\n### Don't allow usernames in passwords\n\nTo enforce the policy that prevents a password from containing a username, do\nthe following:\n\n1. Verify the your `postgresql.conf` file\n [preloads password validation library](#preload-password-db-library).\n\n2. Set the\n [`password.enforce_password_does_not_contain_username`](/alloydb/omni/current/docs/reference/password-policy-flags#enforce-password-does-not-contain-username) to `ON`.\n\nFor example, to ensure that a password doesn't contain a username as a\nsubstring, you set the following in your `postgresql.conf` file:\n\n- `password.enforce_password_does_not_contain_username = ON`\n\nIf this flag is set, then the following operation fails because the password\n`alex-secret` contains the username `alex`: \n\n CREATE USER alex WITH PASSWORD 'alex-secret';\n\nWhat's next\n-----------\n\n- Learn how to [backup and restore AlloyDB AlloyDB Omni](/alloydb/omni/current/docs/backup-overview)\n- [Create a read-only replica](/alloydb/omni/current/docs/set-up-read-replica)"]]