How do I create an encrypted password in MATLAB?
5 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2012 年 1 月 12 日
編集済み: MathWorks Support Team
2023 年 3 月 27 日
I am writing a set of MATLAB scripts that communicate with a database. I need to prompt the user for a password to get into the database. Currently, when the user enters the password you can actually see the password as the user is typing. Is there a way to get a character (such as *) to appear on the display instead of letters/numbers while the user is entering the password?
採用された回答
MathWorks Support Team
2023 年 5 月 19 日
編集済み: MathWorks Support Team
2023 年 3 月 27 日
Currently, you cannot have letters or numbers appear as particular characters in MATLAB. This has been forwarded to our development staff to be considered for a future version of MATLAB.
Please consider the following workarounds:
1. Use an ActiveX control
2. Set the foreground color to be the same as the background color, the typing will not be visible.
h = uicontrol('Style','Edit','ForeGroundColor',[.75 .75 .75]);
3. Use a font that does not appear as normal letters.
h = uicontrol('Style','Edit','Fontname','symbol');
4. A file exchange submission that replaces the characters typed with asterisks can be found in the following link:
https://www.mathworks.com/matlabcentral/fileexchange/8499-login
Also, keep in mind if you are creating an application that will be used on a number of different platforms you will need to use a font name particular for each platform.
See the following as a possible MATLAB code workaround:
function passwd_test
u = uicontrol('style','edit','enable','inactive','backgroundcolor','w',...
'units','norm',...
'position',[.1 .1 .5 .1],...
'tag','edit')
u = uicontrol('style','text','enable','inactive','backgroundcolor','w',...
'units','norm',...
'position',[.1 .25 .5 .1],...
'tag','text')
set(gcf,'keypressfcn', {@handle_passwd})
function handle_passwd(h,eventData)
CK = get(gcf,'currentkey');
h_disp = findobj(gcbf,'tag','text');
h_asterix = findobj(gcbf,'tag','edit');
if gco == h_asterix,
str = get(h_disp,'string');
if strcmp(CK,'backspace'),
% Do something here if the backspace key was pressed
if length(str) > 1,
str = str(1:end-1);
end
elseif strcmp(CK,'space')
str = [str,' '];
else
str = [str,CK];
end
set(h_disp,'string',str);
set(h_asterix,'string',char(ones(1,length(str))*double('*')));
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!