Print Page | Close Window

Detecting Invalid Password?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2340
Printed Date: 24 Jun 25 at 11:26AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Detecting Invalid Password?
Posted By: waynefulcher
Subject: Detecting Invalid Password?
Date Posted: 18 Jul 12 at 4:01PM
I am using Delphi 7 and QuickPDF 7.26.
I have a program that allows the user to select a PDF file from disk and it gives them the option to input a password in case the PDF is secured.
 
My program then calls SetAdvancePassword(), then LoadFromFile().
Then it loops for each page calling RenderPageToStream().
I then display the rendered image so the user can view each page.
All of this code works fine if...The PDF is not secured or the PDF is secured and the user has supplied the correct password.
 
But if the PDF is secured and the user supplies an incorrect password, I can't seem to figure out how to "detect" that. The LoadFromFile() method works and returns a 1.
The RenderPageToStream() also returns a 1 and the LastRenderError is blank. So I have no way to detect it actually fails. The result is the rendered image is just a blank white image.
 
The odd thing is when I run my program from the Delphi IDE, the call to RenderPageToStream() actually throws an exception message that shows up in the Delphi IDE but the QuickPDF library must be trapping that exception because I do not get an exception in my code. So once again I cant seem to figure out how to detect an invalid password.
 
Any help would be much appriciated.
Wayne
 



Replies:
Posted By: ExchangeViews
Date Posted: 20 Jul 12 at 8:54AM
Use QuickPDF 8.xx.


Posted By: waynefulcher
Date Posted: 20 Jul 12 at 1:53PM
I have no problem upgrading but are you saying 8.x will work differently than 7.26 as far as what I described?
Can you tell me what will be different in 8.x that would allow me to have a controlled test to see if the password is invalid?
Does RenderPageToStream() return somethig different? Does LoadFromFile() return something different?


Posted By: Wheeley
Date Posted: 20 Jul 12 at 8:39PM
Straight from the upgrade to 8 technical guide:

The LoadFrom* functions now return 1 on success and 0 on failure. In QPL v7 these functions would return 2 if an encrypted document made use of object streams or cross reference streams. This is no longer necessary as these functions have a new password parameter. If the wrong password is given, the LoadFrom* functions will return 0 and the LastErrorCode function will return error code 404.

Wheeley


Posted By: ExchangeViews
Date Posted: 21 Jul 12 at 8:11AM
V8.x does not use SetAdvancePassword(). You need to directly use loadfromfile('test.pdf', password);
Upgraded version return correct value for invalid password. You can try the trial version.


Posted By: AndrewC
Date Posted: 23 Jul 12 at 7:54AM
LoadFromFile should return "2" if the password is incorrect in QPL 7.26.  This used to be quite reliable in 7.xx and this logic was moved to QPL 8.xx where it now returns a 0 and LastErrorCode is set to 404 - InvalidPassword.

Does the PDF file have a User and Master password ?  It could also depend on the PDF file itself. If the file has a blank user password but has a master password then the file will still open correctly with QP.SetAdvancePassword('');  - It could be that the renderer is having a problem rendering the file.  Where does the Exception happen and what is the exception reporting ?

If you send me the PDF I will see if I can reproduce the Exception in QPL 8.xx.  There have been many bugs and enhancements added to QPL 8.xx compared to 7.26.

Andrew.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk