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

Fangjun Jiang
Fangjun Jiang 2011년 9월 13일
+1. I'd like to know if there is a way to implement it.
Aaqib Khan
Aaqib Khan 2017년 8월 23일
편집: Aaqib Khan 2017년 8월 23일
function password()
X = inputdlg('PLEASE ENTER THE PASSWORD TO PROCEED');
x = str2double(X{1,1});
password = 123; % SET IT HERE MANUALLY
if (x == password)
uiwait(msgbox('Password Correct !!'));
else
while (x ~= 123)
if (x == password)
uiwait(msgbox('Password Correct !!'));
break;
else
uiwait(errordlg('Incorrect Password !!'));
X = inputdlg('PLEASE ENTER THE PASSWORD TO PROCEED');
x = str2double(X{1,1});
end
end
uiwait(msgbox('Password Correct !!'));
end
Matthew Cribb
Matthew Cribb 2020년 5월 14일
There is a flaw in this code. If you exit or cancel out in the passwork input dlgbx it will produce an error.
Matthew Cribb
Matthew Cribb 2020년 5월 14일
편집: Matthew Cribb 2020년 5월 14일
%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 2020년 5월 19일
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!

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2011년 9월 14일

2 개 추천

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

Serge
Serge 2023년 4월 7일
편집: Serge 2023년 4월 8일
I wasn't hapy with eithe of those, so I made my own:

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 13일

0 개 추천

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

Jan
Jan 2011년 9월 15일
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 2011년 9월 16일
You could use one-way hashing, like Unix does.

댓글을 달려면 로그인하십시오.

Oleg Komarov
Oleg Komarov 2014년 11월 25일

0 개 추천

An addition to the list by Jan FEX: passfield.
sonali mishra
sonali mishra 2017년 12월 8일

0 개 추천

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

Walter Roberson
Walter Roberson 2017년 12월 8일
Several of the file exchange contributions listed in the above responses hide the answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2011년 9월 13일

편집:

2023년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by