Refactor to allow overriding the credentials controller.

Now this controller can be easily overridden in the main app.

Example and tests included.