From cc56a30b19be16ddbd2b7da33b59e9ecfaedd8e8 Mon Sep 17 00:00:00 2001 From: Henry Luetcke <hluetcke@ethz.ch> Date: Wed, 13 May 2020 16:39:44 +0200 Subject: [PATCH] test native Matlab password dialog --- textValue.m | 51 +++++++++++++++++++++++++++++++++ user_url_pw_input.m | 69 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 textValue.m create mode 100644 user_url_pw_input.m diff --git a/textValue.m b/textValue.m new file mode 100644 index 00000000000..36ed8d5df90 --- /dev/null +++ b/textValue.m @@ -0,0 +1,51 @@ +function pass = textValue +% Create figure and components. + +ScreenSize = get(0,'ScreenSize'); +fig = uifigure('Position',[(ScreenSize(3:4)-[300 75])/2 300 75]); +fig.CloseRequestFcn = @(fig,event)my_closereq(fig); + +lbl = uilabel(fig, ... + 'Position',[10 10 150 20]); + +txt = uieditfield(fig,... + 'Position',[10 40 150 20], ... + 'Tag', 'my_textfield', ... + 'ValueChangedFcn', @textChanged, ... + 'ValueChangingFcn', @textChanging, ... + 'UserData', ''); + + +uiwait(fig) + + function my_closereq(fig,selection) + pass = get(txt,'UserData'); + delete(fig) + + end + +disp(pass) + +end + +% Callback functions +function textChanged(txt) +% disp(txt.UserData) +end + +function textChanging(txt, event) +disp(event.Value); + +if isempty(txt.UserData) + txt.UserData = event.Value; +else + txt.UserData = append(txt.UserData, event.Value(end)); +end + +val = event.Value; +val(1:length(val)) = '*'; +txt.Value = val; + +end + + diff --git a/user_url_pw_input.m b/user_url_pw_input.m new file mode 100644 index 00000000000..3dfd54607b3 --- /dev/null +++ b/user_url_pw_input.m @@ -0,0 +1,69 @@ +function [url, user, pass] = user_url_pw_input +%user_url_pw_input +% Return the URL, user name and password for the openBIS server + +url = 'https://XYZ.ethz.ch/openbis:8443'; +user = ''; +pass = ''; + +ScreenSize = get(0,'ScreenSize'); +hfig = figure('Menubar','figure', ... + 'Units','Pixels', ... + 'Resize','on', ... + 'NumberTitle','off', ... + 'Name',['Enter openBIS credentials'], ... + 'Position',[ (ScreenSize(3:4)-[200 75])/2 300 200], ... + 'Color',[0.8 0.8 0.8], ... + 'WindowStyle','modal'); + +% hedit = uicontrol('Parent',hfig, ... +% 'Style','Edit', ... +% 'Enable','inactive', ... +% 'Units','Pixels','Position',[49 28 202 22], ... +% 'FontSize',15, ... +% 'String',[], ... +% 'BackGroundColor',[0.7 0.7 0.7]); + +huser = uicontrol('Parent',hfig, ... + 'Style','Text', ... + 'Tag','user', ... + 'Units','Pixels','Position',[1 30 198 18], ... + 'FontSize',15, ... + 'BackGroundColor',[1 1 1]); + +hpass = uicontrol('Parent',hfig, ... + 'Style','Text', ... + 'Tag','password', ... + 'Units','Pixels','Position',[51 30 198 18], ... + 'FontSize',15, ... + 'BackGroundColor',[1 1 1]); + + +set(hfig,'KeyPressFcn',{@keypress_Callback, huser, hpass}, ... + 'CloseRequestFcn','uiresume') + +uiwait +pass = get(hpass,'userdata'); +delete(hfig) + + +function keypress_Callback(~,data, huser, hpass) + +pass = get(hpass,'userdata'); + +switch data.Key + case 'backspace' + pass = pass(1:end-1); + case 'return' + uiresume + return + otherwise + try + pass = [pass data.Character]; + catch + disp('Some error occured during password entry!') + end +end + +set(hpass,'userdata',pass) +set(hpass,'String',char('*'*sign(pass))) \ No newline at end of file -- GitLab