Simulink Mask Editor - Lock parameter access with password
14 views (last 30 days)
Show older comments
Hello everybody, I hope you are fine and have good wealth.
I am using the mask editor to create costum libraries and would like to lock the access to some parameters with a password, so that the user can have some kind of "admin" access to some parameters using this password. Is this possible and if yes, which approach can you recommend?
Thanks everybody for your valuable help and with best wishes,
Lars
0 Comments
Answers (2)
Ayush
on 31 Jul 2024
Edited: Ayush
on 31 Jul 2024
Hello Lars,
Yes, it is possible to create password-protected access to certain parameters in Simulink using the Mask Editor by creating a custom script that introduces protected parameters with their intial visibility turned off and can be accessed once the condition is set to true, in your case when the admin inputs the password. You can utilize the following example code for your reference:
% Create the Password Field
addParameter(maskObj, 'admin_password', 'Type', 'edit', 'Prompt', 'Enter Admin Password');
% Create the Protected Parameters
addParameter(maskObj, 'protected_param1', 'Type', 'edit', 'Prompt', 'Protected Parameter 1', 'Visible', 'off');
addParameter(maskObj, 'protected_param2', 'Type', 'edit', 'Prompt', 'Protected Parameter 2', 'Visible', 'off');
% Add the Callback Script
maskObj.Parameters(admin_password).Callback = @checkPassword;
function checkPassword
blk = gcb;
enteredPassword = get_param(blk, 'admin_password');
correctPassword = 'your_secure_password';
% Condition to check if the entered password matches the correct password
if strcmp(enteredPassword, correctPassword)
% Toggle Visibility 'On'
set_param(blk, 'protected_param1', 'Visible', 'on');
set_param(blk, 'protected_param2', 'Visible', 'on');
else
% Toggle Visibility 'Off'
set_param(blk, 'protected_param1', 'Visible', 'off');
set_param(blk, 'protected_param2', 'Visible', 'off');
end
end
Hope this helps you!
0 Comments
Lars Lindner
on 15 Nov 2024 at 10:52
He Ayush, thank you very much for your answer.
I am actually using Matlab R2022a and would like to ask, where this code must be executed? Should it be defined in the Code tab of the mask editor (Initialization oder Parameter callback section?) or does it need to be executed as an additional script
How do I define the "maskObj" variable?
Thanks Ayush for your valuable help and with best wishes,
Lars
0 Comments
See Also
Categories
Find more on Interactive Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!