> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/appendixes/contrib/passwordcheck.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# F.24. passwordcheck — 驗證密碼強度 \#

### F.24. passwordcheck — 驗證密碼強度 [#](#passwordcheck) <a href="#passwordcheck" id="passwordcheck"></a>

[F.24.1. 設定參數](#passwordcheck-configuration-parameters)

`passwordcheck` 模組會在使用者透過 [CREATE ROLE](https://docs.postgresql.tw/19/reference/sql-commands/sql-createrole.md) 或 [ALTER ROLE](https://docs.postgresql.tw/19/reference/sql-commands/sql-alterrole.md) 設定密碼時檢查其密碼。 如果密碼被判定為過於脆弱，系統會拒絕該密碼，並使該指令以錯誤終止。

若要啟用此模組，請將 `'$libdir/passwordcheck'` 新增至 `postgresql.conf` 中的 [shared\_preload\_libraries](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-SHARED-PRELOAD-LIBRARIES)，然後重新啟動伺服器。

你可以修改原始碼，讓此模組符合你的需求。舉例來說，你可以使用 [CrackLib](https://github.com/cracklib/cracklib) 檢查密碼；只需取消 `Makefile` 中兩行內容的註解，然後重新建置模組即可。（基於授權因素，我們無法預設納入 CrackLib。） 未使用 CrackLib 時，模組會強制套用數項簡單的密碼強度規則；你可以視需要修改或擴充這些規則。

#### 注意

為防止未加密的密碼透過網路傳送、寫入伺服器日誌，或以其他方式遭資料庫管理員竊取，PostgreSQL 允許使用者提供預先加密的密碼。許多用戶端程式會使用此功能，並在將密碼傳送至伺服器之前加密密碼。

這會限制 `passwordcheck` 模組的實用性，因為在這種情況下，它只能嘗試猜測密碼。因此，如果你的安全性需求很高，不建議使用 `passwordcheck`。 使用 GSSAPI 等外部驗證方法（請參閱[第 20 章](https://docs.postgresql.tw/19/server-administration/client-authentication.md)）比依賴資料庫中的密碼更安全。

或者，你可以修改 `passwordcheck`，使其拒絕預先加密的密碼；但強制使用者以明文設定密碼也有其自身的安全風險。

#### F.24.1. 設定參數 [#](#passwordcheck-configuration-parameters) <a href="#passwordcheck-configuration-parameters" id="passwordcheck-configuration-parameters"></a>

`passwordcheck.min_password_length` (`integer`)

可接受的最小密碼長度，以位元組為單位。預設值為 8。只有 超級使用者可以變更此設定。

##### 註

如果使用者提供預先加密的密碼，此參數不會產生任何作用。

一般會在 `postgresql.conf` 中設定此參數，但超級使用者可以在自己的工作階段中即時變更它。典型的用法如下：

```

# postgresql.conf
passwordcheck.min_password_length = 12
```

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/passwordcheck.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/appendixes/contrib/passwordcheck.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
