do some work when user login or register in drupal6 I want to set some fields in database when user registers or login. I know I don't have to change the drupal core and I guess I should use hooks for this purpose but I don't know how and where. 

Should I write a new module and implement a hook inside it? What hook?
In drupal 6, there is a function named hook_user.

By using this hook in your custom module. You can do watever you want. Remember to put condition in this by '$op' like

function hook_user($op, &amp;$edit, &amp;$account, $category = NULL) {
  if($op == 'login') {
    //do watever you want
  }
}