How to get environment password in script/function
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Gareth
el 14 de Dic. de 2018
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.
Respuestas (2)
Guillaume
el 14 de Dic. de 2018
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.
0 comentarios
Gareth
el 15 de Dic. de 2018
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 comentario
Guillaume
el 15 de Dic. de 2018
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.
Ver también
Categorías
Más información sobre Startup and Shutdown 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!