Home > m > mysql > logindlg.m

logindlg

PURPOSE ^

LOGINDLG Dialog for visually secure login.

SYNOPSIS ^

function [varargout]=logindlg(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: logindlg.m,v 1.4 2008/02/22 10:58:34 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [varargout]=logindlg(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: logindlg.m,v 1.4 2008/02/22 10:58:34 hewitson Exp $
0028 
0029 if nargin == 2
0030   Login    = varargin{1};
0031   password = varargin{2};
0032 else
0033   Login = '';
0034   password = '';
0035 end
0036 
0037 for i=1:numel(password), passwordHidden(i)='*'; end
0038 if ~exist('passwordHidden','var'), passwordHidden = ''; end
0039 
0040 % Get Properties
0041 Color = get(0,'DefaultUicontrolBackgroundcolor');
0042 
0043 set(0,'Units','characters')
0044 Screen = get(0,'screensize');
0045 Position = [Screen(3)/2-17.5 Screen(4)/2-4.75 35 9.5];
0046 set(0,'Units','pixels')
0047 
0048 
0049 % Create the GUI
0050 gui.main = dialog('HandleVisibility','on',...
0051     'IntegerHandle','off',...
0052     'Menubar','none',...
0053     'Name','LTPDA Repository Login',...
0054     'NumberTitle','off',...
0055     'Tag','logindlg',...
0056     'Color',Color,...
0057     'Units','characters',...
0058     'Userdata','logindlg',...
0059     'Position',Position);
0060 
0061     set(gui.main,'Closerequestfcn',{@Cancel,gui.main},'Keypressfcn',{@Escape,gui.main})
0062 
0063 % Texts
0064 gui.login_text = uicontrol(gui.main,'Style','text','FontSize',8,'HorizontalAlign','center','Units','characters','String','Login','Position',[1 7.65 33 1]);
0065 gui.password_text = uicontrol(gui.main,'Style','text','FontSize',8,'HorizontalAlign','center','Units','characters','String','Password','Position',[1 4.15 33 1]);
0066 
0067 % Edits
0068 gui.edit1 = uicontrol(gui.main,'Style','edit','FontSize',8,'HorizontalAlign','center','BackgroundColor','white','Units','characters','String',Login,'Position',[1 6.02 33 1.7]);
0069 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);
0070 
0071 % Buttons
0072 gui.OK = uicontrol(gui.main,'Style','push','FontSize',8,'Units','characters','String','OK','Position',[2 .2 15 1.7],'Callback',{@OK,gui.main});
0073 gui.Cancel = uicontrol(gui.main,'Style','push','FontSize',8,'Units','characters','String','Cancel','Position',[18 .2 15 1.7],'Callback',{@Cancel,gui.main});
0074 
0075 setappdata(0,'logindlg',gui) % Save handle data
0076 setappdata(gui.main,'Check',0) % Error check setup. If Check remains 0 an empty cell array will be returned
0077 
0078 uicontrol(gui.edit1) % Make the first edit box active
0079 
0080 % Pause the GUI and wait for a button to be pressed
0081 uiwait(gui.main)
0082 
0083 Check = getappdata(gui.main,'Check'); % Check to see if a button was pressed
0084 
0085 % Format output
0086 if Check == 1
0087     Login = get(gui.edit1,'String');
0088     Password = get(gui.edit2,'Userdata');
0089     
0090     varargout(1) = {Login};
0091     varargout(2) = {Password};
0092 else % If OK wasn't pressed output nothing
0093         varargout(1) = {[]};
0094         varargout(2) = {[]};
0095 end
0096 
0097 delete(gui.main) % Close the GUI
0098 setappdata(0,'logindlg',[]) % Erase handles from memory
0099 
0100 %% Hide Password
0101 function KeyPress_Function(h,eventdata,fig)
0102 % Function to replace all characters in the password edit box with
0103 % asterixes
0104 password = get(h,'Userdata');
0105 key = get(fig,'currentkey');
0106 
0107 switch key
0108     case 'backspace'
0109         password = password(1:end-1); % Delete the last character in the password
0110     case 'return'  % This cannot be done through callback without making tab to the same thing
0111         gui = getappdata(0,'logindlg');
0112         OK([],[],gui.main);
0113     case 'tab'  % Avoid tab triggering the OK button
0114         gui = getappdata(0,'logindlg');
0115         uicontrol(gui.OK);
0116     otherwise
0117         password = [password get(fig,'currentcharacter')]; % Add the typed character to the password
0118 end
0119 
0120 SizePass = size(password); % Find the number of asterixes
0121 if SizePass(2) > 0
0122     asterix(1,1:SizePass(2)) = '*'; % Create a string of asterixes the same size as the password
0123     set(h,'String',asterix) % Set the text in the password edit box to the asterix string
0124 else
0125     set(h,'String','')
0126 end
0127 
0128 set(h,'Userdata',password) % Store the password in its current state
0129 
0130 %% Cancel
0131 function Cancel(h,eventdata,fig)
0132 uiresume(fig)
0133 
0134 %% OK
0135 function OK(h,eventdata,fig)
0136 % Set the check and resume
0137 setappdata(fig,'Check',1)
0138 uiresume(fig)
0139 
0140 %% Escape
0141 function Escape(h,eventdata,fig)
0142 % Close the login if the escape button is pushed and neither edit box is
0143 % active
0144 key = get(fig,'currentkey');
0145 
0146 if isempty(strfind(key,'escape')) == 0 && h == fig
0147     Cancel([],[],fig)
0148 end

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003