Home > api-openbis-matlab > passcode.m

passcode

PURPOSE ^

PASSCODE password input dialog box.

SYNOPSIS ^

function pass = passcode

DESCRIPTION ^

PASSCODE  password input dialog box.
  passcode creates a modal dialog box that returns user password input.
  Given characters are substituted with '*'-Signs like in usual password dialogs.

  usage:
  password = PASSCODE

 Adapted from https://www.mathworks.com/matlabcentral/fileexchange/6590-passcode
 Version: v1.2 (03-Mar-2008)
 Author:  Elmar Tarajan [MCommander@gmx.de]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pass = passcode
0002 %PASSCODE  password input dialog box.
0003 %  passcode creates a modal dialog box that returns user password input.
0004 %  Given characters are substituted with '*'-Signs like in usual password dialogs.
0005 %
0006 %  usage:
0007 %  password = PASSCODE
0008 %
0009 % Adapted from https://www.mathworks.com/matlabcentral/fileexchange/6590-passcode
0010 % Version: v1.2 (03-Mar-2008)
0011 % Author:  Elmar Tarajan [MCommander@gmx.de]
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

Generated on Tue 06-Jul-2021 16:01:18 by m2html © 2005