简体   繁体   中英

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.

You should be able to use

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

if($valid) {
    //
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM