Date: Fri, 21 Nov 2003 17:44:29 +0000 From: Jez Hancock <jez.hancock@munk.nu> To: questions@freebsd.org Subject: Re: How can I set a password from STDIN? Message-ID: <20031121174429.GA69747@users.munk.nu> In-Reply-To: <3FBD97CE.8982F285@ene.asda.gr> References: <3FBD97CE.8982F285@ene.asda.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031121174429.GA69747>