Should take a look at how python's Flask handles the problem: http://flask.pocoo.org/snippets/31/ and create a Plug accordingly.
How to make it modular so that it won't depend on a particular backend for user/pass-hash checks?
How to keep track of valid nonces?