I'm building a MATLAB application that authenticates a user's credentials. I want to read in his password, and I want to hide his typed credentials somehow.
Some constraints:
- I have to account for windows as well as linux/mac users.
- I can't be assured of any programs (perl/python/VBS) in the user system.
Here's what I've tried:
Straight-up GUIDE
Works, but not an option as the user is likely to be running matlab in -nodesktop
(or -nodisplay
) mode.
MATLAB + Java
console.readPassword. This messes up my terminal horribly.
system() calls
Essentially I call bash or dos scripts based on OS.
I have the following call for linux/mac:
[status cred] = system('stty -echo; read cred; stty echo;echo ""; echo "$cred"');
This is supposed to pick up the user credentials and dump that on to 'cred'. I've checked that it works in the regular terminal, but executing it in MATLAB causes nothing to be output, and a Ctrl-C is required to bring back the >>
prompt.
MATLAB Perl
The Windows MATLAB packages Perl, as pointed out in comments. I tried the following snippet:
use Term::ReadKey;
use Term::ReadLine;
ReadMode('noecho');
$yesnoline = Term::ReadLine->new("foo");
$pass = $yesnoline->readline();
printf "$pass";
ReadMode('restore');
And then called it as [result status] = perl('my_perl.pl')
. Works great on Linux.
On Windows:
res =
GetConsoleMode failed, LastError=|6| at ReadKey.pm line 264.
sta =
9
My searches so far suggest that it's a problem related to the packaged version of perl for windows.
Any idea what's happening in the above approaches?