<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>

CC BY-SA 4.0
2023-10-10T22:06:27.687Z
2023-10-10T22:06:27.687Z
Mats Mikkel Rummelhoff
<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>

<users><craft4>
Get list of user logins
# 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() %}


    
        Username
        Last login
    
    {% for user in users %}
        
            {{ user.username }}
            {{ user.lastLoginDate|default ? user.lastLoginDate|date('Y-m-d H:i:s') }}
        
    {% endfor %}


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.


---

