Home > m > gui > gltpda > loginLTPDA.m

loginLTPDA

PURPOSE ^

LOGINDLG Dialog for visually secure login.

SYNOPSIS ^

function [varargout]=loginLTPDA(varargin)

DESCRIPTION ^

 LOGINDLG   Dialog for visually secure login.

 Author: Jeremy Smith
 Date: September 24, 2005
 Last Edit: July 7, 2006
 Version: 1.2
 Tested on: Matlab 7.0.4.365 (R14) Service Pack 2 and Matlab 7.1 SP 3
 Description: custom login dialog because Matlab doesn't have an option
       for characters in an edit field to be replaced by asterixes
       (password security)

 =======================================================================
 ============== UPDATED FOR USE WITH LTPDA PACKAGE =====================
 =======================================================================
 
 The function now has a fixed supported syntax to call:
          [login password] = loginLTPDA('userID','password')
 or
          [login password] = loginLTPDA('','')

 It will only accept 2 string inputs and it will provide 2 string
 outputs.
 If 2 empty strings are passed the edit fields will be empty, otherwise
 they'll show as defaults the strings passed.

   $Id: loginLTPDA.m,v 1.2 2008/03/04 05:00:52 nicola Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [varargout]=loginLTPDA(varargin)
0002 % LOGINDLG   Dialog for visually secure login.
0003 %
0004 % Author: Jeremy Smith
0005 % Date: September 24, 2005
0006 % Last Edit: July 7, 2006
0007 % Version: 1.2
0008 % Tested on: Matlab 7.0.4.365 (R14) Service Pack 2 and Matlab 7.1 SP 3
0009 % Description: custom login dialog because Matlab doesn't have an option
0010 %       for characters in an edit field to be replaced by asterixes
0011 %       (password security)
0012 %
0013 % =======================================================================
0014 % ============== UPDATED FOR USE WITH LTPDA PACKAGE =====================
0015 % =======================================================================
0016 %
0017 % The function now has a fixed supported syntax to call:
0018 %          [login password] = loginLTPDA('userID','password')
0019 % or
0020 %          [login password] = loginLTPDA('','')
0021 %
0022 % It will only accept 2 string inputs and it will provide 2 string
0023 % outputs.
0024 % If 2 empty strings are passed the edit fields will be empty, otherwise
0025 % they'll show as defaults the strings passed.
0026 %
0027 %   $Id: loginLTPDA.m,v 1.2 2008/03/04 05:00:52 nicola Exp $
0028 
0029 Login    = varargin{1};
0030 password = varargin{2};
0031 for i=1:numel(password), passwordHidden(i)='*'; end
0032 if ~exist('passwordHidden','var'), passwordHidden = ''; end
0033 
0034 % Get Properties
0035 Color = get(0,'DefaultUicontrolBackgroundcolor');
0036 
0037 set(0,'Units','characters')
0038 Screen = get(0,'screensize');
0039 Position = [Screen(3)/2-17.5 Screen(4)/2-4.75 35 9.5];
0040 set(0,'Units','pixels')
0041 
0042 
0043 % Create the GUI
0044 gui.main = dialog('HandleVisibility','on',...
0045     'IntegerHandle','off',...
0046     'Menubar','none',...
0047     'Name','LTPDA Login',...
0048     'NumberTitle','off',...
0049     'Name','Login',...
0050     'Tag','logindlg',...
0051     'Color',Color,...
0052     'Units','characters',...
0053     'Userdata','logindlg',...
0054     'Position',Position);
0055 
0056     set(gui.main,'Closerequestfcn',{@Cancel,gui.main},'Keypressfcn',{@Escape,gui.main})
0057 
0058 % Texts
0059 gui.login_text = uicontrol(gui.main,'Style','text','FontSize',8,'HorizontalAlign','center','Units','characters','String','Login','Position',[1 7.65 33 1]);
0060 gui.password_text = uicontrol(gui.main,'Style','text','FontSize',8,'HorizontalAlign','center','Units','characters','String','Password','Position',[1 4.15 33 1]);
0061 
0062 % Edits
0063 gui.edit1 = uicontrol(gui.main,'Style','edit','FontSize',8,'HorizontalAlign','center','BackgroundColor','white','Units','characters','String',Login,'Position',[1 6.02 33 1.7]);
0064 gui.edit2 = uicontrol(gui.main,'Style','edit','FontSize',8,'HorizontalAlign','center','BackgroundColor','white','Units','characters','String',passwordHidden,'Position',[1 2.52 33 1.7],'KeyPressfcn',{@KeyPress_Function,gui.main},'Userdata',password);
0065 
0066 % Buttons
0067 gui.OK = uicontrol(gui.main,'Style','push','FontSize',8,'Units','characters','String','OK','Position',[2 .2 15 1.7],'Callback',{@OK,gui.main});
0068 gui.Cancel = uicontrol(gui.main,'Style','push','FontSize',8,'Units','characters','String','Cancel','Position',[18 .2 15 1.7],'Callback',{@Cancel,gui.main});
0069 
0070 setappdata(0,'logindlg',gui) % Save handle data
0071 setappdata(gui.main,'Check',0) % Error check setup. If Check remains 0 an empty cell array will be returned
0072 
0073 uicontrol(gui.edit1) % Make the first edit box active
0074 
0075 % Pause the GUI and wait for a button to be pressed
0076 uiwait(gui.main)
0077 
0078 Check = getappdata(gui.main,'Check'); % Check to see if a button was pressed
0079 
0080 % Format output
0081 if Check == 1
0082     Login = get(gui.edit1,'String');
0083     Password = get(gui.edit2,'Userdata');
0084     
0085     varargout(1) = {Login};
0086     varargout(2) = {Password};
0087 else % If OK wasn't pressed output empty fields
0088         varargout(1) = {''};
0089         varargout(2) = {''};
0090 end
0091 
0092 delete(gui.main) % Close the GUI
0093 setappdata(0,'logindlg',[]) % Erase handles from memory
0094 
0095 %% Hide Password
0096 function KeyPress_Function(h,eventdata,fig)
0097 % Function to replace all characters in the password edit box with
0098 % asterixes
0099 password = get(h,'Userdata');
0100 key = get(fig,'currentkey');
0101 
0102 switch key
0103     case 'backspace'
0104         password = password(1:end-1); % Delete the last character in the password
0105     case 'return'  % This cannot be done through callback without making tab to the same thing
0106         gui = getappdata(0,'logindlg');
0107         OK([],[],gui.main);
0108     case 'tab'  % Avoid tab triggering the OK button
0109         gui = getappdata(0,'logindlg');
0110         uicontrol(gui.OK);
0111     otherwise
0112         password = [password get(fig,'currentcharacter')]; % Add the typed character to the password
0113 end
0114 
0115 SizePass = size(password); % Find the number of asterixes
0116 if SizePass(2) > 0
0117     asterix(1,1:SizePass(2)) = '*'; % Create a string of asterixes the same size as the password
0118     set(h,'String',asterix) % Set the text in the password edit box to the asterix string
0119 else
0120     set(h,'String','')
0121 end
0122 
0123 set(h,'Userdata',password) % Store the password in its current state
0124 
0125 %% Cancel
0126 function Cancel(h,eventdata,fig)
0127 uiresume(fig)
0128 
0129 %% OK
0130 function OK(h,eventdata,fig)
0131 % Set the check and resume
0132 setappdata(fig,'Check',1)
0133 uiresume(fig)
0134 
0135 %% Escape
0136 function Escape(h,eventdata,fig)
0137 % Close the login if the escape button is pushed and neither edit box is
0138 % active
0139 key = get(fig,'currentkey');
0140 
0141 if isempty(strfind(key,'escape')) == 0 && h == fig
0142     Cancel([],[],fig)
0143 end

Generated on Mon 31-Mar-2008 21:41:00 by m2html © 2003