The reason that you don't want to do this is that if some cracker finds a workaround for any security obstacles put in his way (which he will), it means a total breach of security. You don't want that.
If you do go through with it (which you shouldn't), encrypt the passwords and implement other security mechanisms (like emailing the user for authentication). IIRC, the Expect module would be of use for interfacing with passwd (or any other program that involves multi-step user input...within reason).