asking for a password or code.

63 views (last 30 days)
Ejay Kasai
Ejay Kasai on 13 Sep 2011
Edited: Serge on 8 Apr 2023
hey guys, what's the code that matlab program will ask for a password?if password is incorrect, the program will terminate. if it's correct the program will continue.
  5 Comments
Matthew Cribb
Matthew Cribb on 14 May 2020
Edited: Matthew Cribb on 14 May 2020
%Use return to quit the function when exiting or canceling the inputdlg,
%(i.e. when x is empty) i.e. put this right after the inputdlg..
if isempty(x)
return
end
%str2double() wnt wont work on emty cll array, so must not be...therefore
%this following evaulation of X wont occur if it is empty it is after the prev.
% if isempty(x)-->return-->end
X = str2double(x{1,1});
Pedro Rodriguez Alicea
Pedro Rodriguez Alicea on 19 May 2020
why cant i use this type of code for a gui?
i want to as soon as i run my gui get a pop up that requests a password
thank you!

Sign in to comment.

Accepted Answer

Jan
Jan on 14 Sep 2011
There are some submissions in the FEX for a password input dialog:
But the abortion of the program must be implemented by the user. If you distribute your program as M- or P-files, the protection level will be limited, see FEX: passprotect. Breaking this protection will take several minutes only. But at least the user needs a criminal intent to do this.
  1 Comment
Serge
Serge on 7 Apr 2023
Edited: Serge on 8 Apr 2023
I wasn't hapy with eithe of those, so I made my own:

Sign in to comment.

More Answers (4)

Fangjun Jiang
Fangjun Jiang on 13 Sep 2011
MATLAB doesn't have that function. You can use input() to ask the user to type in some numbers or letters. You have to do encryption yourself if you want to implement some type of password checking procedure.
The simplest way to do might be this. Ask the user to type in a password, compare it with a pre-defined one. The pre-defined one is stored in your source code (.m file). But you can use pcode() to convert your .m file to .p file. Since .p file is encrypted, you have some type of encryption protection. But it's not easy to implement a password changing functionality.
  2 Comments
Jan
Jan on 15 Sep 2011
The functionality to change passwords is usually obtained by writing them encrypted to the disk. But the main problem is the limited protection level of P-coded files: Although you cannot convert them to M-code, you can use the debugger to inspect what's going on and catch calls to toolbox-function by shadowing them by local functions, e.g. "function R=strcmp(a,b), disp(a), disp(b), R=true", which will reveal the password very fast, if it is compare by STRCMP. SWITCH/CASE is one of the few possibilities to compare a password without using a shadowable built-in function.
Walter Roberson
Walter Roberson on 16 Sep 2011
You could use one-way hashing, like Unix does.

Sign in to comment.


Walter Roberson
Walter Roberson on 13 Sep 2011

Oleg Komarov
Oleg Komarov on 25 Nov 2014
An addition to the list by Jan FEX: passfield.

sonali mishra
sonali mishra on 8 Dec 2017
how to make the password hide?? and i also want to make a userID box with this password box... can u help me how to create these.....
  1 Comment
Walter Roberson
Walter Roberson on 8 Dec 2017
Several of the file exchange contributions listed in the above responses hide the answer.

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!