Skip to content
Snippets Groups Projects
Commit 7e7a1d0a authored by Henry Luetcke's avatar Henry Luetcke Committed by Adam Laskowski
Browse files

implement native Matlab password dialog v0.1

parent cc56a30b
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
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
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
function [url, user, pass] = user_url_pw_input_dialog
%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');
fig = uifigure('Name', 'Enter openBIS credentials', 'Position',[(ScreenSize(3:4)-[300 75])/2 400 150]);
fig.CloseRequestFcn = @(fig,event)my_closereq(fig);
% URL label and text field
lbl_url = uilabel(fig, 'Text', 'URL:', ...
'Position',[10 120 80 20]);
txt_url = uieditfield(fig,...
'Position',[70 120 280 20], ...
'Value', url, ...
'Tag', 'url_textfield');
% User label and text field
lbl_user = uilabel(fig, 'Text', 'User:', ...
'Position',[10 90 80 20]);
txt_user = uieditfield(fig,...
'Position',[70 90 280 20], ...
'Value', user, ...
'Tag', 'user_textfield');
% Password label and text field
lbl_pass = uilabel(fig, 'Text', 'Password:', ...
'Position',[10 60 80 20]);
txt_pass = uieditfield(fig,...
'Position',[70 60 280 20], ...
'Tag', 'pass_textfield', ...
'ValueChangingFcn', @textChanging, ...
'UserData', '');
% Push button to accept entries
btn = uibutton(fig,'push', ...
'Position',[150 10 100 40], ...
'Text', 'Connect', ...
'FontWeight', 'bold', ...
'ButtonPushedFcn', @(btn,event) buttonPushed(btn, fig));
uiwait(fig)
% run this when figure closes
function my_closereq(fig,selection)
url = get(txt_url, 'Value');
user = get(txt_user, 'Value');
pass = get(txt_pass,'UserData');
delete(fig)
end
end
% Callback functions
function textChanging(txt, event)
% replace typed text with stars
% Todo: handle delete / backspace
% disp(event.Value);
if isempty(txt.UserData)
txt.UserData = event.Value;
else
txt.UserData = append(txt.UserData, event.Value(end));
end
val = event.Value;
if ~isempty(val)
val(1:length(val)) = '*';
else
val = '*';
end
txt.Value = val;
end
function buttonPushed(btn, fig)
% close the figure, call CloseRequestFcn before
close(fig)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment