How to get environment password in script/function

15 ビュー (過去 30 日間)
Johnny Birch
Johnny Birch 2018 年 12 月 14 日
コメント済み: Guillaume 2018 年 12 月 15 日
I know it is possible to extract environmental parameters like the username like this
getenv('username')
but is it also possible to extract the password?
  2 件のコメント
GT
GT 2018 年 12 月 14 日
Hi Johnny,
I am not sure if I understand your question, but usually it is considered a really bad idea to have enviroment variables with passwords... this is a major security flaw.
That being said you can alway use:
setenv('PATH', [getenv('PATH') ';D:\mypath']);
so that you create/add a particular variable to your enviroment like you would do with the path. Again just want to make sure you know if the password is on the enviroment then EVERY application can see it and it is typically a bad idea. Please further explain what you are trying to do as maybe the enviroment is not the best way to solve your problem.
Johnny Birch
Johnny Birch 2018 年 12 月 14 日
Hi GT, thanks for taking the time for answering. I am still a novice in Matlab programming so maybe some of my descriptions are a bit clumbsy. So here is what I am trying to do.
I want to write a program which takes the windows login info (name + password) and use these to access a database where some data is accessible for data analysis. Is this possible?

サインインしてコメントする。

回答 (2 件)

Guillaume
Guillaume 2018 年 12 月 14 日
If you are talking about the password that was used by the user to log into their Windows/Mac/Linux/Whatever account, then absolutely not, for the simple reason that it's not stored at all in environment variables by any operating system. That would be a major security hole.
For that matter, the OS makes it as hard as possible for any program to even access that password. The OS should never give you the actual password, it will give you a token instead.
In any case, matlab does not have tools to access the security details of the logged in user. You could possibly do that by calling .Net functions directly from matlab (on Windows only). On other OSes, you'll certainly have to write your own mex code. As said, you still won't get the password, just a security token that you'll pass to the other application. On windows, you'll also get a UAC prompt.
How to actually do that, I don't know exactly as it's not something I have ever had a need to. If you were interested to do that with .Net, you'd have to read the System.Security documentation. It's not going to be trivial, so the answer to your is this possible is going to be: not without a lot of work.

GT
GT 2018 年 12 月 15 日
The MathWorks does have a Database toolbox which does exactly what you are describing. That being said you probably would have to hard code the username/password. Indeed a common approach is to reuse credentials for database access, what I have seen people do is create a simple userinterface inside MATLAB that asks people for those credentials and then the program takes that info when pulling/fetching data.
Check out the Database Toolbox to see if this would help. I am sure that you could potentially with some effort use the .NET or java interface to access databases like this, as MATLAB can call both natively.
  1 件のコメント
Guillaume
Guillaume 2018 年 12 月 15 日
My understanding is that the question is not about accessing databases, which can indeed be done easily with or even without the database toolbox, but about reusing the windows password to access such database.
It is not possible to retrieve the user password (windows does not even know what it is, it only stores a hash of it). While it would be possible to retrieve a security token for the logged in account and pass that to a database (if the database support it), the details how to do that would be fairly complex.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by