# PasswordPolicy

Password policy for User Pools.

- Source: [`aws-cognito/lib/user-pool.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts#L443)
- Type last changed: v2.178.0 · 6 Feb 2025

## Example

TypeScript:

```ts
new cognito.UserPool(this, 'myuserpool', {
  // ...
  passwordPolicy: {
    minLength: 12,
    requireLowercase: true,
    requireUppercase: true,
    requireDigits: true,
    requireSymbols: true,
    tempPasswordValidity: Duration.days(3),
  },
});
```

Python:

```python
cognito.UserPool(self, "myuserpool",
    # ...
    password_policy=cognito.PasswordPolicy(
        min_length=12,
        require_lowercase=True,
        require_uppercase=True,
        require_digits=True,
        require_symbols=True,
        temp_password_validity=Duration.days(3)
    )
)
```

Java:

```java
UserPool.Builder.create(this, "myuserpool")
        // ...
        .passwordPolicy(PasswordPolicy.builder()
                .minLength(12)
                .requireLowercase(true)
                .requireUppercase(true)
                .requireDigits(true)
                .requireSymbols(true)
                .tempPasswordValidity(Duration.days(3))
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
new UserPool(this, "myuserpool", new UserPoolProps {
    // ...
    PasswordPolicy = new PasswordPolicy {
        MinLength = 12,
        RequireLowercase = true,
        RequireUppercase = true,
        RequireDigits = true,
        RequireSymbols = true,
        TempPasswordValidity = Duration.Days(3)
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
cognito.NewUserPool(this, jsii.String("myuserpool"), &UserPoolProps{
	// ...
	PasswordPolicy: &PasswordPolicy{
		MinLength: jsii.Number(12),
		RequireLowercase: jsii.Boolean(true),
		RequireUppercase: jsii.Boolean(true),
		RequireDigits: jsii.Boolean(true),
		RequireSymbols: jsii.Boolean(true),
		TempPasswordValidity: awscdk.Duration_Days(jsii.Number(3)),
	},
})
```

## Properties

- `minLength`: number = 8 — Minimum length required for a user's password.

- `passwordHistorySize`: number — The number of previous passwords that you want Amazon Cognito to restrict each user from reusing.

  **Default:** undefined - Cognito default setting is no restriction

  `passwordHistorySize` cannot be set when `featurePlan` is `FeaturePlan.LITE`.

- `requireDigits`: boolean = true — Whether the user is required to have digits in their password.

- `requireLowercase`: boolean = true — Whether the user is required to have lowercase characters in their password.

- `requireSymbols`: boolean = true — Whether the user is required to have symbols in their password.

- `requireUppercase`: boolean = true — Whether the user is required to have uppercase characters in their password.

- `tempPasswordValidity`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.days(7) — The length of time the temporary password generated by an admin is valid.

  This must be provided as whole days, like Duration.days(3) or Duration.hours(48).
  Fractional days, such as Duration.hours(20), will generate an error.
