---
title: "unlockWithPassword(_:)"
framework: coregraphics
role: symbol
role_heading: Instance Method
path: "coregraphics/cgpdfdocument/unlockwithpassword(_:)"
---

# unlockWithPassword(_:)

Unlocks an encrypted PDF document when a valid password is supplied.

## Declaration

```swift
func unlockWithPassword(_ password: UnsafePointer<CChar>) -> Bool
```

## Parameters

- `password`: A pointer to a string that contains the password.

## Return Value

Return Value A Boolean that, if true, indicates that the document has been successfully unlocked. If the value is false, the document has not been unlocked.

## Discussion

Discussion Given an encrypted PDF document and a password, this function does the following: Sets the lock state of the document, based on the validity of the password. Returns true if the document is unlocked. Returns false if the document cannot be unlocked with the specified password. Unlocking a PDF document makes it possible to decrypt the document and perform other privileged operations. Different passwords enable different operations.

## See Also

### Working with an Encrypted PDF Document

- [isEncrypted](coregraphics/cgpdfdocument/isencrypted.md)
- [allowsCopying](coregraphics/cgpdfdocument/allowscopying.md)
- [allowsPrinting](coregraphics/cgpdfdocument/allowsprinting.md)
- [isUnlocked](coregraphics/cgpdfdocument/isunlocked.md)
