On Fri, Nov 21, 2003 at 06:42:54AM +0200, Lefteris Tsintjelis wrote:
> Hi,
> 
> Would anyone know how can I set or change a password from STDIN? Neither
> passwd or pw seem to accept STDIN.
As someone else mentioned, use -h switch to pw to modify a user password
command line using pw.

As an example a recent PHP application I worked on I added this as a
comment:

/*
use popen to create a stream to the
command:
pw adduser -q -u user -g group \
        -s shell -d /home/user -c comment -h 0

and then write the password to the file pointer created
by popen.  This effectively adds the user to the passwd database
whilst at same time setting the password.

This saves listing the password in 'ps' listings.
*/
// adduser command:
$pw_cmd = $cfg['prog']['pw']." useradd ".$data["username"]
        ." -g g".$data["id"]
        ." -s $shell "
        ." -d ".$data["root"]
        ." -c \"".$data["name"]."\""
        ." -h 0";

// Open a uni-directional stream to the command:
$fp = popen($pw_cmd, "w");

// Execute the command, passing the $data["password"] to it:
fwrite($fp, $data["password"]);

// Close the pipe:
fclose($fp);

-- 
Jez Hancock
 - System Administrator / PHP Developer

http://munk.nu/
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to