[[["容易理解","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\u003eThis page details how to enhance the security of AlloyDB for PostgreSQL instances by setting password policies for database users authenticating with the built-in, password-based method.\u003c/p\u003e\n"],["\u003cp\u003ePassword policies can enforce complexity requirements such as minimum length, the inclusion of uppercase, numeric, and non-alphanumeric characters, and they can prevent usernames from being used in passwords.\u003c/p\u003e\n"],["\u003cp\u003ePassword policies are applied only to newly created passwords and entered as plain text, with existing passwords remaining unchanged by policy updates.\u003c/p\u003e\n"],["\u003cp\u003ePassword expiration policies can be enforced by setting the password.enforce_expiration flag to ON, as well as defining the password.expiration_in_days and password.notify_expiration_in_days flags for expiration periods and notifications.\u003c/p\u003e\n"],["\u003cp\u003eAlternatively, it is recommended to utilize Identity and Access Management (IAM) based authentication as a more secure and reliable substitute to password-based methods.\u003c/p\u003e\n"]]],[],null,["# Manage built-in authentication using password policies\n\nThis page describes how you can set and manage password policies for database\nusers of your AlloyDB for PostgreSQL instances.\n\nFor an overview of authentication methods available in AlloyDB,\nsee [Authentication](/alloydb/docs/connection-overview#authn).\n\nAbout password policies\n-----------------------\n\nIf your application's database users authenticate with your\nAlloyDB instances using the built-in, password-based method, then\nyou can make authentication more secure by enforcing strong passwords. You can\ndefine and enable password enforcement by\n[setting a password policy on your instances](#set-password-policy).\n| **Note:** As a secure and reliable alternative to password-based authentication, consider using authentication based on Identity and Access Management (IAM). For more information, see [Manage IAM authentication](/alloydb/docs/manage-iam-authn).\n\n### Limitations of password policies\n\nAlloyDB 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 instance password policy\n-------------------------------\n\nYou can set a password policy on an instance by\n[configuring password flags on an instance](/alloydb/docs/instance-configure-database-flags).\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 supports,\nsee [Password policy flags](/alloydb/docs/reference/password-policy-flags).\n\n### Enforce password complexity\n\nTo enforce a password-complexity policy, do the following:\n\n1. Set the [`password.enforce_complexity`](/alloydb/docs/reference/password-policy-flags#enforce_complexity) flag to `ON`.\n2. Use [password policy flags](/alloydb/docs/reference/password-policy-flags) to 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\nmust set the following flags:\n\n- `password.enforce_complexity` to `ON`\n- `password.min_uppercase_letters` flag to `1`\n- `password.min_numerical_chars` flag to `1`\n- `password.min_pass_length` flag to `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. Set the\n [`password.enforce_expiration`](/alloydb/docs/reference/password-policy-flags#enforce_expiration)\n flag to `ON`.\n\n2. Set the\n [`password.expiration_in_days`](/alloydb/docs/reference/password-policy-flags#expiration_in_days)\n flag to the number of days after a password is set that it expires.\n\n3. Set the\n [`password.notify_expiration_in_days`](/alloydb/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\nset the following:\n\n- `password.enforce_expiration` to `ON`\n- `password.expiration_in_days` flag to `30`\n- `password.notify_expiration_in_days` flag to `15`\n\nIf the password of a user expires, that user can't connect to the\nAlloyDB Omni instance. To reset the password of a user, see\n[Change the password of a database user](/alloydb/docs/database-users/about#change-password).\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\n- Set the [`password.enforce_password_does_not_contain_username`](/alloydb/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:\n\n- `password.enforce_password_does_not_contain_username` to `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- [Manage AlloyDB user roles](/alloydb/docs/database-users/manage-roles)\n- [Manage IAM authentication](/alloydb/docs/database-users/manage-iam-auth)"]]