# Get Authentication

Sean's pick this week is GetAuthentication by Stefan.

I was recently asked about a simple way to password protect an executable compiled with MATLAB Compiler. The customer's goal was that this would be on a shared machine and only authorized users would be able to use the executable.

It occurred to me that I frequently use a MATLAB-based password box every time I upload a file to our FTP or SFTP site to share with customers. Digging into the code there, I discovered this file and was excited to see it publicly available on the File Exchange.

To use it to protect your executable, simply call it in a wrapper function to decide whether to open the main executable or quit. Here's a simple example that gives access to my four dogs to see a picture of themselves.

function authenticateApp()
% application.

unames = {'Zoey', 'Mya', 'Lexi', 'Lilly'};
passwords  = {'MilkB0ne', 'Dent@Stix', 'Pupp3roni', 's0ck\$'};

% Try three times
for ii = 1:3
% Get authentication
[user, pass] = GetAuthentication();

useridx = ismember(unames,user);
if nnz(useridx)
% If yes, does the password match for that user?

% Open application here:
imshow('fourdogs.jpg')

break
end
end
end
end


Calling it:

authenticateApp

### Compiling

Now if you want to compile this, make the authentication wrapper the main function and your app will have this protection around it.

### Suggestion

My only suggestion would be for GetAuthentication to pass back a third output argument about whether the user hit the cancel button. Right now, if cancel is hit, it just returns empty for password and username. This is ambiguous to hitting okay with empty password and username which is a challenge to handle if you want to use it in a loop like I did.