Answers.Body: <p>Craft only stores the most recent login date for users (i.e. the <code>lastLoginDate</code>). To get a list of all users and their last login date, you could do something like this:</p>
  <pre><code>{% set users = craft.users.can('accessCp').all() %}
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Username&lt;/th&gt;
          &lt;th&gt;Last login&lt;/th&gt;
      &lt;/tr&gt;
      {% for user in users %}
          &lt;tr&gt;
              &lt;td&gt;{{ user.username }}&lt;/td&gt;
              &lt;td&gt;{{ user.lastLoginDate|default ? user.lastLoginDate|date('Y-m-d H:i:s') }}&lt;/td&gt;
          &lt;/tr&gt;
      {% endfor %}
  &lt;/table&gt;
  </code></pre>
  <p>If you need to retain a more comprehensive <em>login history</em>, as opposed to only the most recent login date, you could try <a href="https://plugins.craftcms.com/audit?craft4" rel="nofollow noreferrer">the Audit plugin</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-10T22:06:27.687Z
Answers.LastActivityDate: 2023-10-10T22:06:27.687Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I would like to get a list of every login of a user. I know I can get a certain user with <code>craft.users()</code> but as far as I have seen, I get data for <code>lastLoginDate</code> only.</p>
  <p>Is there a way to get a complete list of all logins? Is this information even stored?</p>
  
Tags: <users><craft4>
Title: Get list of user logins
ThreadText: # Get list of user logins
  
  (Asked by: username_0 on 2023-10-10)
  
  I would like to get a list of every login of a user. I know I can get a certain user with `craft.users()` but as far as I have seen, I get data for `lastLoginDate` only.
  
  Is there a way to get a complete list of all logins? Is this information even stored?
  
  **Tags:** users, craft4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-10. Score: 3
  
  Craft only stores the most recent login date for users (i.e. the `lastLoginDate`). To get a list of all users and their last login date, you could do something like this:
  
  ```
  {% set users = craft.users.can('accessCp').all() %}
  
  <table>
      <tr>
          <th>Username</th>
          <th>Last login</th>
      </tr>
      {% for user in users %}
          <tr>
              <td>{{ user.username }}</td>
              <td>{{ user.lastLoginDate|default ? user.lastLoginDate|date('Y-m-d H:i:s') }}</td>
          </tr>
      {% endfor %}
  </table>
  
  ```
  
  If you need to retain a more comprehensive *login history*, as opposed to only the most recent login date, you could try [the Audit plugin](https://plugins.craftcms.com/audit?craft4).
  
  
  ---
  
  