How to allow usage or view of a Simulink model based on certain conditions?

6 views (last 30 days)
I want to protect my Simulink model, and only allow users to view its contents (or to simulate it or generate code) based on certain conditions. This conditions include the current date (so that I can make the permission for my model expire after certain amount of time), or the username.
Is there any workflow I can follow to achieve this? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2021
Edited: MathWorks Support Team on 19 Jan 2021
In Simulink, the use of protected models through a password allows the model's accessibility to be restricted by the user for view, modification, simulation or code generation. 
Simulink supports a feature for which the password can be introduced programmatically. This allows having a separate "unlocking script", that would write down the password in the model when certain conditions are met (such as date and username). 
In order to protect the password in the script, this can be p-coded, which will provide an encrypted p-file that can be shared with the users that will access the model, similar to a key to open the model. 
As an example, consider the case in which a user would like to protect their model from view by other users. They could use the function 
 to set the password for their protected model and to create an unlocking script that will be p-coded. 
In order to programmatically set up the password in the model:   
% setPassword.m
Simulink.ModelReference.ProtectedModel.setPasswordForView(...
'protected_model_ref','password');
Simulink.ModelReference.protect('protected_model_ref',...
'Webview',true,'Encrypt',true,'Report',true);
As for the script to unlock the model, it can contain an "i"f statement to check for certain conditions, and the write the password accordingly:
% unlockModel.m -> p-code this file to encrypt it.
% if conditions are met
Simulink.ModelReference.ProtectedModel.setPasswordForView(...
'protected_model_ref','password');
% else
% error('You do not have permission to unlock this model') % Display error message
% end
A similar workflow can be followed in order to protect the model from modification
simulation
After having used the file to set the password, the unlocking script can be p-coded and distributed to users. They can then use this file to unlock the model.   

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!