Refactor authentication to make it more secure.