/**
  * Logs this member in
  *
  * @param bool $remember If set to TRUE, the member will be logged in automatically the next time.
  */
 public function logIn($remember = false)
 {
     $this->extend('beforeMemberLoggedIn');
     self::session_regenerate_id();
     Session::set("loggedInAs", $this->ID);
     // This lets apache rules detect whether the user has logged in
     if (Member::config()->login_marker_cookie) {
         Cookie::set(Member::config()->login_marker_cookie, 1, 0);
     }
     // Cleans up any potential previous hash for this member on this device
     if ($alcDevice = Cookie::get('alc_device')) {
         RememberLoginHash::get()->filter('DeviceID', $alcDevice)->removeAll();
     }
     if ($remember) {
         $rememberLoginHash = RememberLoginHash::generate($this);
         $tokenExpiryDays = Config::inst()->get('SilverStripe\\Security\\RememberLoginHash', 'token_expiry_days');
         $deviceExpiryDays = Config::inst()->get('SilverStripe\\Security\\RememberLoginHash', 'device_expiry_days');
         Cookie::set('alc_enc', $this->ID . ':' . $rememberLoginHash->getToken(), $tokenExpiryDays, null, null, null, true);
         Cookie::set('alc_device', $rememberLoginHash->DeviceID, $deviceExpiryDays, null, null, null, true);
     } else {
         Cookie::set('alc_enc', null);
         Cookie::set('alc_device', null);
         Cookie::force_expiry('alc_enc');
         Cookie::force_expiry('alc_device');
     }
     // Clear the incorrect log-in count
     $this->registerSuccessfulLogin();
     $this->LockedOutUntil = null;
     $this->regenerateTempID();
     $this->write();
     // Audit logging hook
     $this->extend('memberLoggedIn');
 }