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 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!