Authentication controller rewritten