With suitable compilation of PHP, it has some functions related to this. Some of them are listed as Experimental: Use at your own risk.
And although I've never looked at it, and hence can't vouch for it, there's also a securepwd class available for download at www.phpclasses.org which you might like to look at.
Or if it's there, you could just make an appropriate system call to passwd...