I understand that you wish to add a 'Single-use' password for your App created using MATLAB App Deisgner. According to my investigation, there is no direct way to add password protection to an App created in MATLAB.
There are a few workarounds which can be referred:
The following MathWorks File Exchange submission proposes to add an HTML component which can act as a Password protected layer.
The following steps can be followed for another workaround:
- While creating a MATLAB App Designer app, add a 'TextField' component for the Password and a 'Label' component for the Login text.
- Now add a 'ValueChanged' callback to your 'Password-TextField' component
- Inside the callback function add a if-check for the correct 'Single-use' password, and add the call for function 'createComponents' there. Here is an example:
function PasswordEditFieldValueChanged(app, event)
value = app.PasswordEditField.Value;
- Now since the 'Code View' of MATLAB App Designer is not editible, you can use the 'Export to .m file' feature from the dropdown of the 'Save' icon to obtain a .m file for the app which can be edited
- Inside the .m file create a private function like 'createLogin' which would initialize the App's Password components. Here is an example:
function createLogin(app)
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
app.PasswordEditFieldLabel = uilabel(app.UIFigure);
app.PasswordEditFieldLabel.HorizontalAlignment = 'right';
app.PasswordEditFieldLabel.Position = [233 44 58 22];
app.PasswordEditFieldLabel.Text = 'Password';
app.PasswordEditField = uieditfield(app.UIFigure, 'text');
app.PasswordEditField.ValueChangedFcn = createCallbackFcn(app, @PasswordEditFieldValueChanged, true);
app.PasswordEditField.Position = [306 44 100 22];
app.UIFigure.Visible = 'on';
- inside 'createComponents' function initialize the component for showing 'You are Logged in!' and delete the 'Password-TextField' component
- Now replace the call for 'createComponents' with 'createLogin' in the public methods
- Run the .m file to test the App
- Now run the 'mcc -m <app-name>' command to create an .exe file from the .m file.
Please refer to the attached .m file to know more.
Hope this can resolve your query. Thanks.