Linux – Changing user password through GUI app

guilinuxpasswd

I was making a GUI application to manage users and groups in Linux!

I'm done with the part where it creates a new user, but stuck with the part where it gives the newly created user a new password.
What my app simply does is to take the required input (username, list of groups, and password) through a GUI and runs a script passing this info as argument.
Let's say we have a user account, xyz.
If I want to change the password for this account, then all I need to do is simply run the command:

passwd xyz

This will ask for new password. Now I can create a new account using scripts because all the required info is passed in the command line.

useradd -m -G users -g "groups" -s /bin/bash "UserName"

I can run a script through Qt app and create the user, but
in passwd cmd, the input is asked in the other line. How does one deal with that?

Best Answer

I think the right answer here is: don't shell to a command-line tool — use a library call. This will let you handle errors better, and avoids risk-prone passing of the password on a command line.

One library you can use is libuser, which is relatively simple and has C and Python bindings.

Related Question