0001 function pass = passcode
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 ScreenSize = get(0,'ScreenSize');
0015 hfig = figure('Menubar','none', ...
0016 'Units','Pixels', ...
0017 'Resize','off', ...
0018 'NumberTitle','off', ...
0019 'Name',['Enter openBIS password'], ...
0020 'Position',[ (ScreenSize(3:4)-[300 75])/2 300 75], ...
0021 'Color',[0.8 0.8 0.8], ...
0022 'WindowStyle','modal');
0023 hedit = uicontrol('Parent',hfig, ...
0024 'Style','Edit', ...
0025 'Enable','inactive', ...
0026 'Units','Pixels','Position',[49 28 202 22], ...
0027 'FontSize',15, ...
0028 'String',[], ...
0029 'BackGroundColor',[0.7 0.7 0.7]);
0030 hpass = uicontrol('Parent',hfig, ...
0031 'Style','Text', ...
0032 'Tag','password', ...
0033 'Units','Pixels','Position',[51 30 198 18], ...
0034 'FontSize',15, ...
0035 'BackGroundColor',[1 1 1]);
0036 hwarn = uicontrol('Parent',hfig, ...
0037 'Style','Text', ...
0038 'Tag','error', ...
0039 'Units','Pixels','Position',[50 2 200 20], ...
0040 'FontSize',8, ...
0041 'String','character not allowed',...
0042 'Visible','off',...
0043 'ForeGroundColor',[1 0 0], ...
0044 'BackGroundColor',[0.8 0.8 0.8]);
0045
0046 set(hfig,'KeyPressFcn',{@keypress_Callback,hedit,hpass,hwarn}, ...
0047 'CloseRequestFcn','uiresume')
0048
0049 uiwait
0050 pass = get(hpass,'userdata');
0051 delete(hfig)
0052
0053
0054 function keypress_Callback(~,data,~,hpass,~)
0055
0056 pass = get(hpass,'userdata');
0057
0058 switch data.Key
0059 case 'backspace'
0060 pass = pass(1:end-1);
0061 case 'return'
0062 uiresume
0063 return
0064 otherwise
0065 try
0066 pass = [pass data.Character];
0067 catch
0068 disp('Some error occured during password entry!')
0069 end
0070 end
0071
0072 set(hpass,'userdata',pass)
0073 set(hpass,'String',char('*'*sign(pass)))
0074