I am new to Unix environment,
What I have to do is to create an API to change the password of a user having an Unix environment.
I am new to Unix environment,
What I have to do is to create an API to change the password of a user having an Unix environment.
Be really careful when dealing with passwords so there is no leak. Use exec() to invoke the system command (typically passwd)
Basically you'll need to work with 'passwd' unix command which is intended for changing the password.
You'll need to call this command from java by using the ProcessBuilder
or the older API Runtime
Now you'll also need to intercept the output of the passwd command if you want to run it interactively (like using some ui to enter the actual password and so on). In this case I would suggest you to read This article
You may consider also using some kind of predefined shell script that will allow to change the password non interactively. In this case you'll just invoke the script and it will do all the work.
Hope this helps
One hint. After you invoke the passwd command, you need to print password 2 times on stdout when system will ask for it.
To see how read form stdin after invoking exec() check:
http://www.ensta-paristech.fr/~diam/java/online/io/javazine.html