Added login function

A lot of dirtywork done, so the rest of the functionality should not be
too hard (no jinx)