0

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.

2
  • Have you written any code so far? If so, post what you've done so we can better assist you. Commented Oct 10, 2012 at 5:59
  • i have search for the code to be implemented as i have never executed a java code in the Unix environment. So i am searching for that also. So far i have searched ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2"); Map<String, String> env = pb.environment(); env.put("VAR1", "myValue"); env.remove("OTHERVAR"); env.put("VAR2", env.get("VAR1") + "suffix"); pb.directory(new File("myDir")); Process p = pb.start(); now i am trying to get the meaning of the variables like myarg1,var,othervar etc Commented Oct 10, 2012 at 7:35

3 Answers 3

2

Be really careful when dealing with passwords so there is no leak. Use exec() to invoke the system command (typically passwd)

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

i have search for the code to be implemented as i have never executed a java code in the Unix environment. So i am searching for that also. So far i have searched ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2"); Map<String, String> env = pb.environment(); env.put("VAR1", "myValue"); env.remove("OTHERVAR"); env.put("VAR2", env.get("VAR1") + "suffix"); pb.directory(new File("myDir")); Process p = pb.start();
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.