# Change password via perl



## macvillage.net (Mar 10, 2003)

Does anyone know how to change a password via perl?  

I am using a Mac OS X box as a fileserver, and am looking ofr a way to change a password via a remote interface....

I know how to secure it properly... just not how to actually change it.

Anyone know of a script already?  or know exactly the commands?


----------



## symphonix (Mar 12, 2003)

I think you might be able to use the niutil shell command to change the password. You might also be able to use the passwd shell command.


----------



## marqrdt (Mar 8, 2005)

You can use the 'passwd' command, but you'll need to interact with it. To do that, you'll need perl's Expect module. I don't believe OS X's perl has Expect included, you'll probably have to install it (go to www.cpan.org for help installing Perl modules). To see if you have Expect installed, run the following command from the Terminal:
perl -mExpect

If it hangs waiting for input, hit ctrl-c-- you're good to go. If it spits back a lengthy error message about "could not find Expect.pm...", you'll have to install it.

Read the perldoc on Expect. There should be several examples there.

Paul M.


----------

