> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# setPassword

> Set the password for backup/recovery.

## Function Signature

```dart theme={null}
Future<void> setPassword(String password)
```

## Description

Sets the password to be used for password-based backup and recovery operations. This should be called before using `backupWallet` or `recoverWallet` with the password method.

<Note>
  The `backupWallet` and `recoverWallet` methods automatically call `setPassword` if a password is provided, so you typically don't need to call this directly.
</Note>

## Parameters

| Parameter  | Type     | Required | Description         |
| ---------- | -------- | -------- | ------------------- |
| `password` | `String` | Yes      | The password to set |

## Returns

**`void`**

## Example

```dart theme={null}
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Set password explicitly
await portal.setPassword('user-password');

// Then backup with password method
final response = await portal.backupWallet(
  method: PortalBackupMethod.password,
);
```

### Typical Usage

Most commonly, you'll pass the password directly to the backup/recovery methods:

```dart theme={null}
// Password is set automatically
final response = await portal.backupWallet(
  method: PortalBackupMethod.password,
  password: 'user-password', // setPassword is called internally
);
```

## Errors

| Code               | Description                           |
| ------------------ | ------------------------------------- |
| `NOT_INITIALIZED`  | Portal was not initialized            |
| `INVALID_PASSWORD` | The password is invalid (e.g., empty) |

## Related

* [Back up a wallet guide](../guide/back-up-a-wallet)
* [backupWallet](./backupwallet)
* [recoverWallet](./recoverwallet)
