MD5 authentication from a database

I’m trying to enable MD5 authentication, using a database to create the password and hash.

I want to use a web-based client, similar SIPML5, or JSSip. The client will receive its password from an application database in the form of an expiring token.
When it registers with the Asterisk server, I want the authentication information to come from the same database, so it will match when it registers with asterisk.

I don’t see how to run the authentication using an external database, or web source.

Do you have any suggestions?