---
title: "unlock(withPassword:)"
framework: pdfkit
role: symbol
role_heading: Instance Method
path: "pdfkit/pdfdocument/unlock(withpassword:)"
---

# unlock(withPassword:)

Attempts to unlock an encrypted document.

## Declaration

```swift
func unlock(withPassword password: String) -> Bool
```

## Parameters

- `password`: The password to unlock an encrypted document (you cannot lock an unlocked PDF document by using an incorrect password).

## Return Value

Return Value true if the specified password unlocks the document, false otherwise.

## Discussion

Discussion If the password is correct, this method returns true, and a PDFDocumentDidUnlockNotification notification is sent. Once unlocked, you cannot use this function to relock the document. If you attempt to unlock an already unlocked document, one of the following occurs: If the document is unlocked with full owner permissions, unlockWithPassword does nothing and returns true. The password string is ignored. If the document is unlocked with only user permissions, unlockWithPassword attempts to obtain full owner permissions with the password string. If the string fails, the document maintains its user permissions. In either case, this method returns true.

## See Also

### Managing Document Security

- [isEncrypted](pdfkit/pdfdocument/isencrypted.md)
- [isLocked](pdfkit/pdfdocument/islocked.md)
- [permissionsStatus](pdfkit/pdfdocument/permissionsstatus.md)
- [Permission Properties](pdfkit/permission-properties.md)
