Beginning of session. How to change a letter to an asterisk in runtime
Beginning of session. How to change a letter to an asterisk in runtime
(OP)
Hi anybody,
I am making a beginning of session figure where a user name and password's fields appears. I need that the password's letters change to asterisks while the user write the letters, you know, as it occurs in others applications. The trouble is how to change the asterisks in runtime. Have you got any idea about it?
Cris





RE: Beginning of session. How to change a letter to an asterisk in runtime
I don't know how to do exactly what you want. However, if you change the 'fontname' property of this edit box to 'tracks' it will do the job better( hide the letters and looks better).
Joe
BSTEX - Equation viewer for Matlab
http://www.geocities.com/bstex2001
RE: Beginning of session. How to change a letter to an asterisk in runtime
1) Start a new gui (Matlab window: File, New, Gui)
2) Add a edit text block (where the user will see asterisks)
3) Double click on the edit text block and change the property String from "Edit Text" to "Enter Password"
3) Add a static text block (where the actual typing will show up)
4) Right click somewhere in the gui figure (not on the edit text block or the static text block), select "View Callbacks", and select "KeyPressFcn". Save the file as test2.fig.
5) Enter the following under
function varargout = figure1_KeyPressFcn(h, eventdata, handles, varargin)
% Capture the key pressed
cc=get(handles.figure1,'CurrentCharacter');
% Get the current string in the edit and static text boxes
str1=get(handles.edit1,'string');
str2=get(handles.text1,'string');
% What is in the edit box
if (strcmp(str1,'Enter Password')==1)
% Edit box has 'Enter Password'
% This letter is the start of the password
str1 = '*';
str2 = cc;
else
% Edit box has something besides 'Enter Password'
% This letter is the next letter in the password
str1 = strcat(str1,'*');
str2 = strcat(str2,cc);
end
% Update the strings
set(handles.edit1,'string',str1);
set(handles.text1,'string',str2);
6) Save the files
7) Run the figure
While the example illustrates the technique, you will probably have to upgrade some things to have a practical, functional code. Typing anywhere in the figure except in the edit box will work as desired. Typing in the edit box still shows up as text. One fix is to just change the edit box enable property to inactive. An alternate fix would be to use a static box instead of an edit box. Since typing anywhere in the figure shows up in the password, a modal figure should be used and the password entry area should dominate that figure.
Also, as implemented, the program echos an asterisk for each character of the password. You could use a random function (or something else) to have just some of the asterisks appear.
If you need additional guidance, let me know.
Cheers
J. Vorwald
RE: Beginning of session. How to change a letter to an asterisk in runtime
Great! Thanks a lot
Perfect! Your solution is very good. In fact, I have applied it to my program. The only trouble is I must set the edit box's enable property to 'off'. Thus, I can use the figure's "currentcharacter" property to show the asterisks in the edit box. To do it the user must do click on the edit box, which is no usual. The user don't see any cursor in the edit box as it is usual. The real problem is the edit box have no "curretcharacter" property. Have you any other idea to solve it?
Thanks in advance,
Cris
RE: Beginning of session. How to change a letter to an asterisk in runtime
As you indicated, you need to do something to prevent the password from showing up. The two options are to turn the enable property to 'off' or to 'inactive'. Both options prevent text from appearing by preventing the box from becomming active. However, changing to enable 'off' changes the font to the inactive font. To get the font back, you can use enable set to inactive, or , you change the font also. I think turning the enable property to inactive is a better option.
Regarding the blinking cursor that normally shows up in an active edit box, there is no cursor control in MatLab. If you have the compiller version, you could write the password box in C/C++ where you have more control.
J. Vorwald