my editbox does not update to '*' when I type my login password, the same code run in matlab 2015a mask my password to '*' but not in 2019a
6 views (last 30 days)
Show older comments
function Password_KeyPressFcn(hObject, eventdata, handles)
global pass;
pass = get(handles.Password,'UserData');
v = double(get(handles.figure1,'CurrentCharacter'));
if v == 8
pass = pass(1:end-1);
set(handles.Password,'string',pass)
elseif any(v == 65:90) || any(v == 97:122) || any(v == 48:57)
pass = [pass char(v)];
else
msgbox({'Invalid Password Character';'Can''t use Special Character'},'warn','modal')
return
end
set(handles.Password,'UserData',pass);
set(handles.Password,'String',char('*'*sign(pass)));
0 Comments
Answers (1)
Rahul
on 16 Jun 2025
I understand that you wish to implement the Password functionality to an Edit Field in GUIDE.
According to my understand in MATLAB 2019a the 'KeyPressFcn' does not work similarly to the previous versions. Hence you can make use of the 'evenData.key' and 'eventData.Character' to obtain the key pressed and the character typed in the Edit Field.
Here is an example of some changes:
function Password_KeyPressFcn(hObject, eventdata, handles)
persistent pass
if isempty(pass)
pass = '';
end
% Handle Backspace
if strcmp(eventdata.Key, 'backspace')
if ~isempty(pass)
pass = pass(1:end-1);
end
% Handle regular characters (letters and numbers)
elseif ~isempty(eventdata.Character) && ...
(ismember(eventdata.Character, ['a':'z', 'A':'Z', '0':'9']))
pass = [pass eventdata.Character];
else
msgbox({'Invalid Password Character';'Can''t use Special Character'},'warn','modal')
return;
end
% Store and mask
set(handles.Password, 'UserData', pass);
set(handles.Password, 'String', repmat('*', 1, numel(pass)));
end
The following MATLAB Answer can also be referred:
The following MathWorks documentations can be referred to know more:
'event.EventData': https://www.mathworks.com/help/matlab/ref/event.eventdata-class.html
Thanks.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!