Skip to main content
Disposition_Dev
Community Expert
Community Expert
September 9, 2016
Answered

Faux "password entry prompt"

  • September 9, 2016
  • 3 replies
  • 1072 views

Hey everyone. Happy Friday!

I'm working on a new function to give managers the ability to bypass a particular safeguard in extenuating circumstances. In the middle of the script execution, if a particular error happens, a scriptUI dialog opens up and asks how to proceed. The user can select "override" which will bring up a prompt box in which a manager can input a password to override. Problem is, the user will be able to clearly see what the manager is typing..

Is there a way to obscure (or simply not show) the text that's being typed in a particular prompt box the same way a password field typically works?

Thanks in advance. 😃

This topic has been closed for replies.
Correct answer Loic.Aigon

Or you can simply use the noecho property that needs to be defined at runtime:

function test() { 

    function getMaskedPassword(charAmt) { 

        var str = ""; 

        for (var i = 0; i < charAmt; i++) { 

            str += "*"; 

        } 

        return str; 

    }; 

    var w = new Window("dialog", "Fake Password"); 

    var s = w.add("statictext", undefined, "Enter Password:"); 

    var e = w.add("edittext", undefined, "", {noecho:true}); 

    e.characters = 20; 

    e.password = "bingo"; 

  

    var btn_ok = w.add("button", undefined, "Ok"); 

 

    btn_ok.onClick = function() {

  var match = e.password==e.text;

  alert(match? "Success!" : "Access DENIED" );

  w.close ( Number ( match ) );

    } 

   

  if ( w.show()==1 ) {

  //password is ok so you can go further

  }

}; 

test(); 

3 replies

Loic.Aigon
Legend
September 16, 2016

How did you happen upon this little trick?

Well, because I just made like you at first and some other folk pointed me out to that same property.

Don't forget the ESTK Object Model Explorer and look carefully at the scriptUI components "properties" section. It can includes gems like this.

Loic

Disposition_Dev
Community Expert
Community Expert
September 14, 2016

Hey guys! Thanks so much for your input.

I got stuck working on a different project shortly after i posted this so i haven't had a chance to try out your suggestions, but I'll let you guys know how it turns out ASAP.

Thanks again.

Silly-V
Legend
September 10, 2016

You can try to use this method, which uses ScriptUI and its 'keydown' event on an edittext element. It uses the "preventDefault()" method to not put the native key's text into the field, so that a custom text can instead be placed. I used the 'keyName' property which puts out uppercase names of the keys, and writes out verbose key names of keys such as "Escape". There's also a 'keyIdentifier' property which provides a character code, which you could also use somehow. In my example, it just gives a basic way to use the keys, but I'm not sure how you'd get the 'text' of the keys such as the !@#$%^&*() characters without having to have some function which takes a keyName or identifier and checks for the alt/cmd/shift buttons also being pressed at the same time to arrive at this text.

In this example the correct password is going to be "bingo" -note case-insensitive- and this hard-coded string can be obscured from the user if your script is exported as binary.

#target illustrator

function test() {

    function getMaskedPassword(charAmt) {

        var str = "";

        for (var i = 0; i < charAmt; i++) {

            str += "*";

        }

        return str;

    };

    var w = new Window("dialog", "Fake Password");

    var s = w.add("statictext", undefined, "Enter Password:");

    var e = w.add("edittext", undefined, "");

    e.characters = 20;

    e.password = "";

    var btn_ok = w.add("button", undefined, "Ok");

    e.onChange = function() {

        if (this.text == "") {

            this.password = "";

        } else {

            this.text = getMaskedPassword(this.password.length);

        }

    };

    e.addEventListener("keydown", function(ev) {

        if (ev.keyName == "Tab" || ev.keyName == "Delete" || ev.keyName == "Escape" || ev.keyName == "Enter") {

            this.notify("onChange");

            return;

        }

        ev.preventDefault();

        this.password += ev.keyName;

        this.text = getMaskedPassword(this.password.length);

    });

    btn_ok.onClick = function() {

        if (e.password.toLowerCase() == "bingo") {

            w.close();

            alert("Success!");

        } else {

            alert("Access DENIED");

            e.text = "";

            e.password = "";

        }

    }

    w.show();

};

test();

CarlosCanto
Community Expert
Community Expert
September 10, 2016

works great, thanks!!

Loic.Aigon
Loic.AigonCorrect answer
Legend
September 12, 2016

Or you can simply use the noecho property that needs to be defined at runtime:

function test() { 

    function getMaskedPassword(charAmt) { 

        var str = ""; 

        for (var i = 0; i < charAmt; i++) { 

            str += "*"; 

        } 

        return str; 

    }; 

    var w = new Window("dialog", "Fake Password"); 

    var s = w.add("statictext", undefined, "Enter Password:"); 

    var e = w.add("edittext", undefined, "", {noecho:true}); 

    e.characters = 20; 

    e.password = "bingo"; 

  

    var btn_ok = w.add("button", undefined, "Ok"); 

 

    btn_ok.onClick = function() {

  var match = e.password==e.text;

  alert(match? "Success!" : "Access DENIED" );

  w.close ( Number ( match ) );

    } 

   

  if ( w.show()==1 ) {

  //password is ok so you can go further

  }

}; 

test();