Is there a way to change a user's password from within code?

52 Views Asked by At

Long story short, I'm trying to implement a password reset feature for a web app. Currently, I'm forking an instance of the passwd program and feeding the current and new passwords to it on stdin. This is less than elegant, and I'd rather not have to parse stderr for the error message when something goes wrong.

It looks like the only way to do this without forking an instance of passwd involves reading and re-writing the shadow password file. That seems a bit risky to me. Is there no __passwd() function for Linux?

0

There are 0 best solutions below