# Password-Protect Presentations in PHP

> Encrypt, detect, validate, open, and decrypt password-protected PowerPoint PPT and PPTX presentations in PHP with Aspose.Slides.

Source: https://docs.aspose.com/slides/php-java/password-protected-presentation/
Updated: 2026-09-04


## **Overview**

An opening password encrypts a presentation. The correct password is required to load and view the presentation content, so this protection provides confidentiality.

An opening password is different from a write-protection password. Write protection restricts modification but does not encrypt the content or prevent the presentation from being loaded. To manage passwords for modifying presentations, see [Write-Protect Presentations](/slides/php-java/write-protected-presentation/).

The workflows below apply to both PPT and PPTX presentations. The examples use both formats where their file-based and stream-based behavior is important.

## **Encrypt a Presentation with an Opening Password**

Use [ProtectionManager::encrypt](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#encrypt) to assign an opening password. Then use [Presentation::save](https://reference.aspose.com/slides/php-java/aspose.slides/presentation/#save) to persist the encrypted presentation.

The following example encrypts a PPTX presentation:

```php
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;

$presentation = new Presentation("pres.pptx");
try {
    $presentation->getProtectionManager()->encrypt("open_password");
    $presentation->save("encrypted-pres.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}
```

## **Keep Document Properties Public**

By default, Aspose.Slides includes document properties in presentation encryption. The [ProtectionManager::setEncryptDocumentProperties](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#setEncryptDocumentProperties) method controls this behavior independently of slide-content encryption. Pass `false` before calling [ProtectionManager::encrypt](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#encrypt) when an indexing, classification, search, or document-management system must read metadata without the opening password.

The following example creates an encrypted PPTX presentation while leaving its built-in document properties public:

```php
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;

$presentation = new Presentation();
try {
    $properties = $presentation->getDocumentProperties();
    $properties->setAuthor("Contoso Knowledge Management");
    $properties->setTitle("Quarterly Product Roadmap");
    $properties->setKeywords("roadmap, planning, internal");

    $presentation->getSlides()->get_Item(0)->setName("Encrypted presentation content");
    $presentation->getProtectionManager()->setEncryptDocumentProperties(false);
    $presentation->getProtectionManager()->encrypt("open_password");
    $presentation->save("public-properties-encrypted.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}
```

Passing `false` to [ProtectionManager::setEncryptDocumentProperties](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#setEncryptDocumentProperties) does not make slides, masters, layouts, shapes, media, or other presentation content public. It affects only document properties. To read those properties without loading the encrypted content, see [Manage Presentation Properties](/slides/php-java/presentation-properties/).

## **Load an Encrypted Presentation**

Set [LoadOptions::setPassword](https://reference.aspose.com/slides/php-java/aspose.slides/loadoptions/#setPassword) to the opening password and pass the options to [Presentation](https://reference.aspose.com/slides/php-java/aspose.slides/presentation/) when loading the file. Loading fails when an opening password is required but the supplied password is missing or incorrect.

```php
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;

$loadOptions = new LoadOptions();
$loadOptions->setPassword("open_password");

$presentation = new Presentation("encrypted-pres.pptx", $loadOptions);
try {
    # Work with the decrypted presentation.
} finally {
    $presentation->dispose();
}
```

## **Remove Encryption from a Presentation**

Load the presentation with its opening password, call [ProtectionManager::removeEncryption](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#removeEncryption), and save the result. The saved presentation can then be loaded without a password.

```php
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;

$loadOptions = new LoadOptions();
$loadOptions->setPassword("open_password");

$presentation = new Presentation("encrypted-pres.pptx", $loadOptions);
try {
    $presentation->getProtectionManager()->removeEncryption();
    $presentation->save("encryption-removed.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}
```

## **Validate an Opening Password Before Loading**

Use [PresentationFactory::getPresentationInfo](https://reference.aspose.com/slides/php-java/aspose.slides/presentationfactory/#getPresentationInfo) to obtain [PresentationInfo](https://reference.aspose.com/slides/php-java/aspose.slides/presentationinfo/) without creating a complete presentation instance. Check [PresentationInfo::isPasswordProtected](https://reference.aspose.com/slides/php-java/aspose.slides/presentationinfo/#isPasswordProtected) before requesting or validating a password. When protection is present, validate the supplied value with [PresentationInfo::checkPassword](https://reference.aspose.com/slides/php-java/aspose.slides/presentationinfo/#checkPassword).

### **File-Path Workflow**

The following example validates an opening password for a PPTX file, passes the validated value to [LoadOptions::setPassword](https://reference.aspose.com/slides/php-java/aspose.slides/loadoptions/#setPassword), and then loads the complete presentation:

```php
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;
use aspose\slides\PresentationFactory;

$filePath = "protected-presentation.pptx";
$password = "open_password";
$presentationInfo = PresentationFactory::getInstance()->getPresentationInfo($filePath);

if (!$presentationInfo->isPasswordProtected()) {
    echo("The presentation does not have an opening password.\n");
} elseif (!$presentationInfo->checkPassword($password)) {
    echo("The opening password is incorrect.\n");
} else {
    $loadOptions = new LoadOptions();
    $loadOptions->setPassword($password);

    $presentation = new Presentation($filePath, $loadOptions);
    try {
        echo("The presentation was validated and loaded successfully.\n");
    } finally {
        $presentation->dispose();
    }
}
```

### **Stream Workflow**

The stream overload of [PresentationFactory::getPresentationInfo](https://reference.aspose.com/slides/php-java/aspose.slides/presentationfactory/#getPresentationInfo) provides the same workflow. Reset the position of a seekable stream before loading the complete presentation from that stream.

The following example uses a PPT file:

```php
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;
use aspose\slides\PresentationFactory;

$password = "open_password";

$presentationStream = new Java("java.io.FileInputStream", "protected-presentation.ppt");
try {
    $presentationInfo = PresentationFactory::getInstance()->getPresentationInfo($presentationStream);

    if (!$presentationInfo->isPasswordProtected()) {
        echo("The presentation does not have an opening password.\n");
    } elseif (!$presentationInfo->checkPassword($password)) {
        echo("The opening password is incorrect.\n");
    } else {
        $presentationStream->getChannel()->position(0);

        $loadOptions = new LoadOptions();
        $loadOptions->setPassword($password);

        $presentation = new Presentation($presentationStream, $loadOptions);
        try {
            echo("The presentation was validated and loaded successfully.\n");
        } finally {
            $presentation->dispose();
        }
    }
} finally {
    $presentationStream->close();
}
```

### **checkPassword Return Values**

[PresentationInfo::checkPassword](https://reference.aspose.com/slides/php-java/aspose.slides/presentationinfo/#checkPassword) returns `true` only when the presentation has an opening password and the supplied password is correct. It returns `false` in each of these cases:

- The password is incorrect.
- The presentation does not have an opening password.
- The supplied password is `null` or empty.

The behavior is the same for PPT and PPTX presentations.

## **Check Whether a Loaded Presentation Is Encrypted**

After loading a presentation with the correct password, inspect [ProtectionManager::isEncrypted](https://reference.aspose.com/slides/php-java/aspose.slides/protectionmanager/#isEncrypted) to confirm that the source presentation was encrypted. To detect opening-password protection before loading, use [PresentationInfo::isPasswordProtected](https://reference.aspose.com/slides/php-java/aspose.slides/presentationinfo/#isPasswordProtected) as shown above.

```php
use aspose\slides\LoadOptions;
use aspose\slides\Presentation;

$loadOptions = new LoadOptions();
$loadOptions->setPassword("open_password");

$presentation = new Presentation("encrypted-pres.pptx", $loadOptions);
try {
    $isEncrypted = $presentation->getProtectionManager()->isEncrypted();
    echo("The presentation is encrypted: " . ($isEncrypted ? "true" : "false") . "\n");
} finally {
    $presentation->dispose();
}
```

## **Security Recommendations**

{{% alert color="warning" title="Security" %}}
Do not log opening passwords or include them in diagnostic messages. Avoid unnecessary repeated validation attempts, keep passwords in memory only as long as needed, and reuse a successful validation result when immediately loading the presentation.

Public document properties may disclose author names, titles, subjects, keywords, company information, comments, and custom values even though the presentation content is encrypted. Encrypt sensitive metadata together with the presentation. Leaving properties public should be an explicit decision made only when systems must index, classify, search, or manage the file without an opening password.
{{% /alert %}}

## **Password-Protect a Presentation Online**

1. Open the [Aspose.Slides Lock](https://products.aspose.app/slides/lock) application.
1. Select or upload the presentation.
1. Enter a password for view protection.
1. Optionally enter a separate password for edit protection.
1. Apply the protection and download the resulting file.

{{% alert color="info" title="See also" %}}
- [Write-Protect Presentations](/slides/php-java/write-protected-presentation/)
- [Digital Signature in PowerPoint](/slides/php-java/digital-signature-in-powerpoint/)
{{% /alert %}}

## **FAQ**

**What is the difference between an opening password and a write-protection password?**

An opening password encrypts the presentation and is required to load its content. A write-protection password restricts modification without encrypting the content.

**Can I validate an opening password without loading all slides?**

Yes. Obtain presentation information, check whether opening-password protection is present, and validate the password before creating a complete presentation instance.

**Can an application read metadata without the opening password?**

Yes, but only when the presentation was encrypted with document-property encryption disabled. The application must then use the document-properties-only loading mode described in [Manage Presentation Properties](/slides/php-java/presentation-properties/).

**Do the password-checking workflows support both PPT and PPTX?**

Yes. File-path and stream-based password detection and validation behave the same for PPT and PPTX presentations.



## Related articles

- [Secure Presentations in PHP](https://docs.aspose.com/slides/php-java/presentation-security/)