Login and Register modified

I have refactored this code and added registration, I hope that this new
method is a little easier to read and more flexible than the previous
one, even if it sacrifices a little speed (has to refresh the page)