Answers.Body: <p>You're probably looking for a combination of:</p>
  
  <p><a href="https://docs.craftcms.com/api/v2/craft-usersessionservice.html#method-login" rel="nofollow noreferrer">craft()->userSession->login()</a></p>
  
  <p>or</p>
  
  <p><a href="https://docs.craftcms.com/api/v2/craft-usersessionservice.html#method-loginbyuserid" rel="nofollow noreferrer">craft()->userSession->loginByUserId()</a></p>
  
  <p>along with setting the <a href="https://docs.craftcms.com/v2/config-settings.html#usersessionduration" rel="nofollow noreferrer">userSessionDuration</a> config setting to a really high value.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-03T20:44:57.867Z
Answers.Text: Have these linked resources moved to a new URL?
Answers.UserDisplayName: buck1112
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-06T08:28:20.683Z
Answers.Text: @buck1112 yup... updated!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-02-25T19:17:38.327Z
Answers.LastActivityDate: 2018-10-06T08:28:08.890Z
Answers.LastEditDate: 2018-10-06T08:28:08.890Z
Answers.UserDisplayName: Brad Bell
Body: <p>In my Controller I created a script to add a user to the database, is there a way I can automatically:</p>
  
  <p>1) Log them in and 
  2) Set a permanent session cookie or similar?</p>
  
  <p>I basically don't want the user to have to ever log in and we will be creating the accounts for them.</p>
  
Tags: <plugin-development><users><cookies>
Title: Automatically Log in User
ThreadText: # Automatically Log in User
  
  (Asked by: username_0 on 2015-02-25)
  
  In my Controller I created a script to add a user to the database, is there a way I can automatically:
  
  1) Log them in and
  2) Set a permanent session cookie or similar?
  
  I basically don't want the user to have to ever log in and we will be creating the accounts for them.
  
  **Tags:** plugin-development, users, cookies
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-25. Score: 3
  
  You're probably looking for a combination of:
  
  [craft()->userSession->login()](https://docs.craftcms.com/api/v2/craft-usersessionservice.html#method-login)
  
  or
  
  [craft()->userSession->loginByUserId()](https://docs.craftcms.com/api/v2/craft-usersessionservice.html#method-loginbyuserid)
  
  along with setting the [userSessionDuration](https://docs.craftcms.com/v2/config-settings.html#usersessionduration) config setting to a really high value.
  
  > **Comments:**
  > **username_2**: Have these linked resources moved to a new URL?  
  > **username_1**: @username_2 yup... updated!  
  
  ---
  
  