# Get User Password Date from internal user source

**URL:** <https://forum.inductiveautomation.com/t/get-user-password-date-from-internal-user-source/51872>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [October 12, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/get-user-password-date-from-internal-user-source/51872 "2021-10-12T19:29:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [October 12, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/get-user-password-date-from-internal-user-source/51872/1 "2021-10-12T19:29:48Z")

</div>

I'm struggling to find the Password Date field that @paul-griffith pointed out to me in this post:

> [@Script function to check if a user password has expired](https://forum.inductiveautomation.com/t/script-function-to-check-if-a-user-password-has-expired/28278/9):
>
> The InternalUserRecord class has a com.inductiveautomation.ignition.gateway.authentication.records.InternalUserRecord#PasswordDate field. You would compare that against the max age set on the user source.

Can someone please help me find this class via the GatewayContext variable?

EDIT:  
This is what I have so far

```auto
import com.inductiveautomation.ignition.common.user.User;
import com.inductiveautomation.ignition.gateway.localdb.persistence.LongField;
import com.inductiveautomation.ignition.gateway.localdb.persistence.PersistenceSession;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import com.inductiveautomation.ignition.gateway.user.UserSourceProfile;

import java.util.Optional;

public class GatewayScriptModule extends AbstractScriptModule {
    private GatewayContext gc;

    public GatewayScriptModule(GatewayContext gc){
        this.gc = gc;
    }
    @Override
    protected LongField getUserPasswordDate(String userSource, String userName){
        UserSourceProfile userSourceProfile = gc.getUserSourceManager().getProfile(userSource);

        gc.getUserSourceManager().findUserProperty()

        try {
            User user = userSourceProfile.getUser(userName);
            user.
        }
        catch(Exception e){
            return null;
        }
    }
}

```

Thanks,  
Brandon

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2021, 8:25pm UTC](https://forum.inductiveautomation.com/t/get-user-password-date-from-internal-user-source/51872/2 "2021-10-12T20:25:52Z")

</div>

You’re going to need to query for the underlying record using the ID provided by the `User` instance (under the assumption that the bare `Serializable` returned by `User.getId()` is always going to be an `Integer`); something like:

```java
    protected Long getUserPasswordDate(String userSource, String userName) {
        try {
            UserSourceProfile userSourceProfile = gc.getUserSourceManager().getProfile(userSource);
            return userSourceProfile.getUser(userName)
                .map(user -> {
                        var query = new SQuery<>(InternalUserRecord.META).eq(InternalUserRecord.UserId, user.getId());
                        return gc.getPersistenceInterface().queryOne(query);
                    }
                ).map(record -> record.getLong(InternalUserRecord.PasswordDate))
                .orElseThrow();
        } catch (Exception e) {
            return null;
        }
    }

```
