Full rewrite of the login system