Simulink Mask Editor - Lock parameter access with password
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lars Lindner
el 9 de Abr. de 2022
Respondida: Lars Lindner
el 15 de Nov. de 2024 a las 10:52
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 comentarios
Respuestas (2)
Ayush
el 31 de Jul. de 2024
Editada: Ayush
el 31 de Jul. de 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 comentarios
Lars Lindner
el 15 de Nov. de 2024 a las 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 comentarios
Ver también
Categorías
Más información sobre Interactive Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!