Arun Arun - 4 months ago 23
PHP Question

How to verify the password in PHPExcel generated ".xls" file?

I am generating

excel
files with extension
.xls
using
PHPExcel
library. The excel file is generating. I am using password protection for the document and made only some fields editable. I am doing an
Export Import
mechanism. It is perfectly working now and I need to add some modification.

My question is

Is it possible to verify the password I given to protect the document? So that I can check it at the time of import

For example

If I protect the document using

$sheet -> getProtection() -> setPassword('MyPassword');


Is there any function like below for checking the password?

$newsheet -> getProtection() -> verifyPassword('MyPassword');


Any help could be appreciated.

Answer

You should be able to use

$hash = $sheet->getProtection()->getPassword(); // returns a hash
$valid = ($hash === PHPExcel_Shared_PasswordHasher::hashPassword($password));

if($valid) {
    //
}
Comments