# Helpers.createPasswordPrompt()

```ts
createPasswordPrompt(container: HTMLElement, options: PasswordPromptOptions): PasswordPrompt
```

"This document is protected · Enter the password to open it." — shown in place when a load rejects with `PASSWORD_ERROR`. A wrong password (resolve `false` from `onUnlock`) shakes the field and says so.

- Kind: static method
- Since: 1.0.0

| Parameter | Type | Description |
| --- | --- | --- |
| `container` | `HTMLElement` | Where the prompt is mounted. |
| `options` | `PasswordPromptOptions` | `{ onUnlock, onCancel?, name?, locale?, icons? }`. `onUnlock(password)` returns `true` / `false` directly or as a promise — `false` shakes the field and says the password was wrong; `onCancel()` when the user gives up; `name` is the file's name to show; `locale` and `icons` as for `createDropZone`. |

Returns `PasswordPrompt`: `{ element, destroy() }`.

```ts
import { createPasswordPrompt, createLoadError, PDFDocument, SDKError } from '@kernstra/pdf-web-sdk';

try {
  doc = await PDFDocument.fromFile(file);
} catch (err) {
  if (err instanceof SDKError && err.code === 'PASSWORD_ERROR') {
    const prompt = createPasswordPrompt(container, {
      name: file.name,
      onUnlock: async (password) => {
        try {
          doc = await PDFDocument.fromFile(file, { password });
          prompt.destroy();
          return true;
        } catch {
          return false; // shakes the field
        }
      },
    });
  } else {
    createLoadError(container, { error: err, onRetry: () => openPdf(file) });
  }
}
```

Part of [Helpers](https://kernstra.com/docs/web-sdk/api/helpers) in the Kernstra Web SDK 1.0.0 API reference.

Web page: https://kernstra.com/docs/web-sdk/api/helpers/createpasswordprompt
