Command for server authentification in script with invisible password

1 vue (au cours des 30 derniers jours)
Hüseyin Uzun
Hüseyin Uzun le 30 Juin 2021
Réponse apportée : Chetan le 10 Mai 2024
I save my data on our server and have to log in with my login data. When I start my matlab script on our server, windows asks me for authentication every time matlab whats to access data (importdata and readtable). Can I store my login data on matlab so that matlab can login itself to our server when the script is running and also make my password invisible?
I want to have the script on our server so that I can access the files that are created from homeoffice and share the files with coworkers.
I use powerfolder via webdav, if this info is also important for you.
run=1;
while true
tic
data=importdata('C:\Users\Hüs\Documents\MATLAB\Datalogger\KlimaLoggProAuto.dat1');
alle=[data(8,1);data(11,1);data(21,1);data(24,1);data(34,1);data(37,1);data(47,1);data(50,1);data(60,1);data(63,1);data(73,1);data(76,1);data(86,1);data(89,1);data(99,1);data(102,1)];
string(alle);
a=split(alle,'"');
Werte=a(:,2)';
Zeit=datetime('now');
Zeit=string(Zeit);
WerteZeit_str=cellstr([Zeit,Werte]);
[succes,message]=xlsappend('Datalogger.xlsx',WerteZeit_str,1);
if run>=144
table=readtable('C:\Users\Hüs\Documents\MATLAB\Datalogger\Datalogger.xlsx');
warning('off','all');
x=table.DatumUndUhrzeit; %Datum und Uhrzeit auslesen
x=x(end-770:end);
time=datetime(datestr((x)));
%Raum 210
temp210=table.Temp_R_210__C; %Temperatur Raum210 auslesen
temp210=temp210(end-770:end);
temp210=str2double(temp210);
hum210=table.Hum___; %Luftfeuchtigkeit Raum210 auslesen
hum210=hum210(end-770:end);
hum210=str2double(hum210);
f210=figure('Name','Room210','visible','off');
hold on;
yyaxis left;
plot(time,temp210);
yyaxis right;
plot(time,hum210);
yyaxis left;
title('Temperature and Humidity Room 210');
ylabel('Temperature in °C');
yyaxis right;
ylabel('Humidity in %');
xtickangle(45),
ax = gca();
ax.XTick = linspace(ax.XTick(1),ax.XTick(end),23);
saveas(f210,'Room210.jpg');
hold off;
run=0;
end
run=run+1;
pause(600-toc)
end

Réponses (1)

Chetan
Chetan le 10 Mai 2024
I understand you're looking for a secure method to manage and use login credentials for server access in MATLAB, with the goal of automating data access and sharing with coworkers remotely, specifically through PowerFolder via WebDAV.
A viable strategy involves utilizing system environment variables to securely store credentials and access them within your scripts using `getenv()`.
This can be accomplished by:
1. Using System Environment Variables with `getenv`:
getenv('USERNAME')
ans = 0x0 empty char array
2. Using a Third-Party dotenv package:
1. Create a `.env` file Save your credentials:
USERNAME=yourUsername
PASSWORD=yourPassword
2. Load Environment Variables in MATLAB: Employ a custom or third-party `dotenv` package to import these credentials into MATLAB's workspace at the start of your script.
3. Use Credentials: The `dotenv` package provides a structure of the variables inside the `.env` file:
env = dotenv.read('.env');
env = struct with fields:
USERNAME: 'yourUsername' PASSWORD: 'yourPassword'
env.USERNAME
ans = 'yourUsername'
env.PASSWORD
ans = 'yourPassword'
Refer to the following MathWorks Documentation for more details:
Hope it helps

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by