Made valid_login function error prone

There were a few expected errors:
 - User does not have a cookie to begin with
 - User tries to temper with the cookie's value