I want to set a cookie, when a user logs in and modify it when he logs out. Can I create a hook that gets executed after a successful login and logout?
Did you take a look at the hooks? There are several that start with the word login, like
login_verify_success, and then there is one called logout process. Have you tried using either of those?