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.6 2008/08/24 14:57:44 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.6 2008/08/24 14:57:44 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    set(0,'Units','pixels')
0035    Screen = get(0,'screensize');
0036    loginSize = [230 130];
0037    Position = [(Screen(3)-loginSize(1))/2 (Screen(4)-loginSize(2))/2 loginSize];
0038 
0039 
0040    % Create the GUI
0041    gui.main = dialog('HandleVisibility','on',...
0042       'Color','white',...
0043       'IntegerHandle','off',...
0044       'Menubar','none',...
0045       'Name','LTPDA Login',...
0046       'NumberTitle','off',...
0047       'Name','Login',...
0048       'Tag','logindlg',...
0049       'Units','pixels',...
0050       'Userdata','logindlg',...
0051       'Position',Position);
0052 
0053    set(gui.main,'Closerequestfcn',{@Cancel,gui.main},'Keypressfcn',{@Escape,gui.main})
0054 
0055    % Texts
0056    gui.login_text = uicontrol(gui.main,'Style','text','BackgroundColor','white','FontSize',8,'HorizontalAlign','center','Units','pixels','String','Login','Position',[0 105 Position(3) 20]);
0057    gui.password_text = uicontrol(gui.main,'Style','text','BackgroundColor','white','FontSize',8,'HorizontalAlign','center','Units','pixels','String','Password','Position',[0 60 Position(3) 20]);
0058 
0059    % Edits
0060    gui.edit1 = uicontrol(gui.main,'Tag','userid','Style','edit','FontSize',8,'HorizontalAlign','center','BackgroundColor','white','Units','pixels','String',Login,'KeyPressfcn',{@KeyPress_Func2,gui.main},'Position',[5 85 Position(3)-10 24],'Userdata',0);
0061    gui.edit2 = uicontrol(gui.main,'Tag','password','Style','edit','FontSize',8,'HorizontalAlign','center','BackgroundColor','white','Units','pixels','String',passwordHidden,'Position',[5 40 Position(3)-10 24],'KeyPressfcn',{@KeyPress_Function,gui.main},'Userdata',password);
0062 
0063    % Buttons
0064    buttonSize = [75 26];
0065    gui.OK = uicontrol(gui.main,'Style','push','FontSize',8,'Units','pixels','String','OK','Position',[Position(3)/2-buttonSize(1)-1 5 buttonSize],'KeyPressFcn',{@OKReturn,gui.main},'Callback',{@OK,gui.main});
0066    gui.Cancel = uicontrol(gui.main,'Style','push','FontSize',8,'Units','pixels','String','Cancel','Position',[Position(3)/2+1 5 buttonSize],'KeyPressFcn',{@CancelReturn,gui.main},'Callback',{@Cancel,gui.main});
0067 
0068    % Images
0069    logosize = [31,31];
0070    dimension = [5 3 logosize];
0071    logo = axes('Parent',gui.main,'Units','pixels','Position',dimension);
0072    image(imread('buttonyes.jpg'),'Parent',logo);
0073    axis(logo,'off');
0074    logosize = [31,31];
0075    dimension = [Position(3)-logosize(1)-5 3 logosize];
0076    logo = axes('Parent',gui.main,'Units','pixels','Position',dimension);
0077    image(imread('buttonno.jpg'),'Parent',logo);
0078    axis(logo,'off');
0079    
0080    setappdata(0,'logindlg',gui) % Save handle data
0081    setappdata(gui.main,'Check',0) % Error check setup. If Check remains 0 an empty cell array will be returned
0082 
0083    uicontrol(gui.edit1) % Make the first edit box active
0084    % uicontrol(gui.OK) % Make the OK button active
0085 
0086    % Pause the GUI and wait for a button to be pressed
0087    uiwait(gui.main)
0088    
0089    try if varargin{3}, welcome2LTPDA(varargin{4},varargin{5}); pause(1); end; catch end
0090 
0091    Check = getappdata(gui.main,'Check'); % Check to see if a button was pressed
0092 
0093    % Format output
0094    if Check == 1
0095       Login = get(gui.edit1,'String');
0096       Password = get(gui.edit2,'Userdata');
0097 
0098       varargout(1) = {Login};
0099       varargout(2) = {Password};
0100    else % If OK wasn't pressed output empty fields
0101       varargout(1) = {''};
0102       varargout(2) = {''};
0103    end
0104 
0105    delete(gui.main) % Close the GUI
0106    setappdata(0,'logindlg',[]) % Erase handles from memory
0107 
0108    %% Hide Password
0109 function KeyPress_Function(h,eventdata,fig)
0110    % Function to replace all characters in the password edit box with
0111    % asterixes
0112    password = get(h,'Userdata');
0113    key = get(fig,'currentkey');
0114 
0115    switch key
0116       case 'backspace'
0117          password = password(1:end-1); % Delete the last character in the password
0118       case 'return'  % This cannot be done through callback without making tab to the same thing
0119          gui = getappdata(0,'logindlg');
0120          OK([],[],gui.main);
0121       case 'tab'  % Avoid tab triggering the OK button
0122          gui = getappdata(0,'logindlg');
0123          uicontrol(gui.OK);
0124       otherwise
0125          password = [password get(fig,'currentcharacter')]; % Add the typed character to the password
0126    end
0127 
0128    SizePass = size(password); % Find the number of asterixes
0129    if SizePass(2) > 0
0130       asterix(1,1:SizePass(2)) = '*'; % Create a string of asterixes the same size as the password
0131       set(h,'String',asterix) % Set the text in the password edit box to the asterix string
0132    else
0133       set(h,'String','')
0134    end
0135 
0136    set(h,'Userdata',password) % Store the password in its current state
0137 
0138 function KeyPress_Func2(h,eventdata,fig)
0139    % To check whenever the user press Enter
0140    if ~isempty(get(fig,'CurrentCharacter')) && real(get(fig,'CurrentCharacter'))==13 && get(h,'UserData')==0
0141       setappdata(fig,'Check',1)
0142       uiresume(fig)
0143    elseif real(get(fig,'CurrentCharacter'))==13
0144       uicontrol(findobj(gcf,'Tag','password'))
0145    else
0146       set(h,'UserData',1)
0147    end
0148 
0149    %% Cancel
0150 function Cancel(h,eventdata,fig)
0151    uiresume(fig)
0152 
0153    %% OK
0154 function OK(h,eventdata,fig)
0155    % Set the check and resume
0156    setappdata(fig,'Check',1)
0157    uiresume(fig)
0158 
0159 function CancelReturn(h,eventdata,fig)
0160    if real(get(fig,'CurrentCharacter'))==13
0161       uiresume(fig)
0162    end
0163 
0164    %% OK
0165 function OKReturn(h,eventdata,fig)
0166    % Set the check and resume
0167    if real(get(fig,'CurrentCharacter'))==13
0168       setappdata(fig,'Check',1)
0169       uiresume(fig)
0170    end
0171 
0172    %% Escape
0173 function Escape(h,eventdata,fig)
0174    % Close the login if the escape button is pushed and neither edit box is
0175    % active
0176    key = get(fig,'currentkey');
0177 
0178    if isempty(strfind(key,'escape')) == 0 && h == fig
0179       Cancel([],[],fig)
0180    end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003