Look for libcrack and setup PHP to use it using the --with-crack switch before compiling (seriously, that's the name of the switch)
Read up on this section of the manual for the rest:
http://www.php.net/manual/en/ref.crack.php
As for 30 day expiry, just set a date when they change their password and check it every time they log in to see if today's date is 30 days or more newer than the one you stored when they changed their password.
Note that the php.ini file has a "auto_prepend_file =" setting you can use to put a simple check like this at the top of every page that the php engine parses.