• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I password-protect a text-field button?

Community Beginner ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

Using Adobe Acrobat DC.

A final button on page one is titled: 'Next Page: ADMIN only'.

How can I password protect the button to where if a student clicks on the button, a password box would pop up (so that access to the next page is restricted to admin personnel only)?

Thanks in advance!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Sep 12, 2016 Sep 12, 2016

Thank you ALL for you insightful wisdom and input to this.

And thank you, gkaiseril, for throwing in a sample script. Indeed, I will commence my Great Experiment and see what I see.

FYI to all: this is not a sensitive or confidential security matter in that the admin page simply duplicates the students Content-area entries from page one (so that our admin person can review the content for final save/printout/distribution)....so even if a student somehow got around the password protection of the hi

...

Votes

Translate

Translate
LEGEND ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

You cannot. You can use JavaScript to lock it, but JavaScript can turned off. Also one can use JavaScript in Reder to list all form fields.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

You can set up the form so that the admin-only page is a hidden template and spawn it when the correct password is entered so that is creates a new page. Whether this is a viable approach depends on how secure it needs to be.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

Fascinating work around, thanks for your suggestion. I setup the admin page as a hidden template (which I just did) and will now try to figure out how to create a JavaScript so that it spawns the hidden template as a visible new page, once the document password is entered....is that what you are saying?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

Yes. The button would have a script that prompts the user for a password and spawns the template if it matches.

You can use the undocumented Collab.hashString method so you don't have to store the actual password in the document.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2016 Sep 11, 2016

Copy link to clipboard

Copied

Of course it's not difficult to see the JavaScripts, to see what they do, and duplicate it without the password. If this is something important, like a qualifying exam, this is not suitable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2016 Sep 11, 2016

Copy link to clipboard

Copied

Only the encoded value of the password's hash string is used in the script which is compared to the result of encoding the user entered password. This is very similar to how Unix system store passwords within the user's system file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2016 Sep 11, 2016

Copy link to clipboard

Copied

Yes, but the JavaScript used when the password is entered is also going to be in the PDF... I'm not going to elaborate on hacking techniques though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2016 Sep 12, 2016

Copy link to clipboard

Copied

Here is a sample scrip that uses the hashString encoded password.

var cTest = app.response({cQuestion: "Enter password:", cTitle: "Password Request", bPassword: true, cLabel: "Password:"});

if(cTest != null) {

var cTestPassword = Collab.hashString(cTest);

if("f1Ez7o1plZdHDei34K4zZC" == cTestPassword)

{

app.alert("valid password", 3, 0);

}

else

{

app.alert("Invalid password", 0, 0);

} // end cTest;

} // end cResponse not null;

One could add a check for the login  name to add another layer of protection and add a password to lock editing of the form.

The string "f1Ez7o1plZdHDei34K4zZC" is obtained by running the Collab.hashString() method in the JavaScript console and it is unique to the required password.

Additional security could be added by not adding the template until the form is returned or moving the data from the returned form to a copy of the form with the template.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 12, 2016 Sep 12, 2016

Copy link to clipboard

Copied

Thank you ALL for you insightful wisdom and input to this.

And thank you, gkaiseril, for throwing in a sample script. Indeed, I will commence my Great Experiment and see what I see.

FYI to all: this is not a sensitive or confidential security matter in that the admin page simply duplicates the students Content-area entries from page one (so that our admin person can review the content for final save/printout/distribution)....so even if a student somehow got around the password protection of the hidden page template, for example, no harm no foul, lol.

Thanks again to ALL of you for your wonderful assistance on this!

John

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2016 Sep 12, 2016

Copy link to clipboard

Copied

I saw this first done by D.P. Story in is AcroTex program. Although there are some special authoring features his product adds to Acrobat, it still uses Acrobat JavaScript for automation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

How do I run the Collab.hashString() method in the JavaScript console?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

Enter this code:

Collab.hashString("some text");

Select it with the mouse and press Ctrl+Enter.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2017 Mar 10, 2017

Copy link to clipboard

Copied

Thank you try67!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

First of all, thanks again for the script!

I have used this script to password-protect a text field formatted as a percentage in a test examination form so that the student cannot enter their own score—only the instructor. What I'm running into is that whether the password is valid or not, the percentage is still entered into the box; i.e., the password works, but doesn't protect the text field to prevent unauthorized users from modifying it. Will someone help with this even though the thread here is old?

Second, is there a command that would replace "app.alert("valid password", 3, 0);" with something that doesn't call the "ding" sound? If the password is invalid, fine, but if it is good, I don't want the instructor to have to listen to that.

Thank you to all! I'm learning as I go.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

How does you protect the text field?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

Thanks to try67 for his comment.

To Bernd Alheit:

I selected the text field, opened the Properties dialog, went to Validation tab, selected Run Custom Validation Script, Edit, pasted in the script, and then closed the modal.

If you know a more appropriate way, I'll be glad to know it.

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

What script does you use?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

The script from @gkaiseril, listed above as the correct answer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2019 Jul 01, 2019

Copy link to clipboard

Copied

The script at reply 8 ask for a password and checks the password. It doesn't lock any field.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2019 Jul 01, 2019

Copy link to clipboard

Copied

Hmmm, okay. Hadn't considered that. What's the purpose of a password? Isn't it to lock whatever it's supposed to protect? I mean, it IS called "password-protect," right?

Regardless, I need to be able to prevent anyone who does not know the password from being able to interact with the field in question. Can anyone help with that?

Also, please help with turning a percentage-formatted text field into one into which a person can enter the numerical percent, instead of the decimal equivalent: "89.5" instead of ".895"

I cannot seem to act on the field once I "get" it with the following code:

var fld = this.getField("Score");

The Console shows this command to be good, but doesn't seem to allow any further operations on the field.

Thanks to all in advance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2019 Jul 01, 2019

Copy link to clipboard

Copied

- There's no real way of doing that using Acrobat JavaScript. If someone is willing enough they'll always be able to find out the password from the code.

- Don't use a percentage field then. Use a regular field with a custom Format script to add the "%" character to the entered value.

- What kind of operations are you trying to perform, exactly?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2019 Jul 01, 2019

Copy link to clipboard

Copied

try67​ Thanks so much.

You know, I'm not really worried about someone trying to hack this. It's not really a big deal, because the instructor is always going to be the last one to see the test, anyway. I'm just trying to save him some frustration. A simple password-protection for a single field is all I need. Alternatively, if I could hide the field so only the instructor could call it into visible mode, that would work too.

As far as the percentage, that's not a big deal, either. I'm working on "nice to have," not "need to have." I'm working with limited space on the forms, so if I don't have to include instructions about how to enter the percentage, that would make things easier for me—I won't have to shuffle things around to make room for that text.

Finally, I'm just picking up js as I go, and don't know how to add a custom Format script for the % character. I guess I can just add a freestanding one to the form in Edit PDF mode or go back to INDD and re-export, but since there are over 200 different iterations of these quizzes that need to be modified in this way, I was hoping for a universal solution. I've downloaded the Acrobat JS API Reference, but that's a big chunk of jerky to chew all at once, especially when you don't really understand the syntax like you should.

Listen, all, I appreciate all your help. I suppose I just need to pay for a js course and really learn what I'm doing.

Thanks,

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

- If you explain how exactly you want this to work, we could probably help you implement it correctly.

- For the format script, it's pretty simple. Use this:

if (event.value) event.value+="%";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2019 Jul 02, 2019

Copy link to clipboard

Copied

Wow, how great, @try67! THANK you! That little line of code did a great job! I'm halfway there, now.

Here's a screenshot of what I have:

Score line.jpg <— your % is working!

What I want to be able to do is password protect the "Score" field so that a failed password challenge does not allow an entry into the field (rejects it), <or> hide the fact that it IS a field as far as the student taking the test is concerned, but allow the instructor to unhide it, enter a score, and leave it visible. IF he decides to print the form, the Score field should print, as well.

As long as it is not OBVIOUS that it can be hacked, I'm not too worried about that, since the instructor will be the last one to see them. Also, these will be school classroom computers that are locked down except for the capabilities needed to take tests and such, so I doubt editing capabilities would be available.

As stated above, I have used the script in reply #8, adding it to the "Properties—>Validate—>Run custom validation script" tab, and it does, in fact, ask for and accept a password, but even if the password test fails, the number entered before the password challenge is still placed in the field. So, if I put 50% in the field and fail the password challenge, 50% is still placed in the field; i.e., anyone can modify the entry with or without the password.  >pulling my hair out!<

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines