Password Management

Last Updated on : 2024-03-20 10:03:02download

This topic describes how to manage a password.

Get the list of created passwords

API description

ILockDevice # void getPasswordList(PasswordListParams params, IThingResultCallback<PasswordListResp> callback);

Parameter description

Parameter Description
params The parameter bean for getting the list of passwords.
params.groupId The ID of the site to which the lock belongs.
params.deviceId The device ID.
params.periodType The search criteria. It defaults to an empty string.
pageNo The requested page number.
pageSize The number of items returned per page.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).getPasswordList(params, new IThingResultCallback<PasswordListResp>() {
    @Override
    public void onSuccess(PasswordListResp result) {
        // Got password list successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        // Failed to get password list
    }
});

Get password details

API description

ILockDevice # void getPasswordDetail(long siteId, String passwordId, IThingResultCallback<PasswordBean> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
passwordId The password ID.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).getPasswordDetail(siteId, passwordId, new IThingResultCallback<PasswordBean>() {
    @Override
    public void onSuccess(PasswordBean result) {
        //Got password details successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to get password details
    }
});

Create a one-time offline password

API description

ILockDevice # void createOncePassword(OncePasswordCreateParams params, IThingResultCallback<PasswordResp> callback);

Parameter description

Parameter Description
params The parameter bean for creating a one-time offline password.
params.groupId The ID of the site to which the lock belongs.
params.deviceId The device ID.
params.passwordName The username for the password.
callback The callback.

Example

OncePasswordCreateParams oncePasswordCreateParams = new OncePasswordCreateParams();
oncePasswordCreateParams.passwordName = "once password name";
oncePasswordCreateParams.groupId = siteId;
oncePasswordCreateParams.deviceId = deviceId;

ThingOSLock.newLockInstance(deviceId).createOncePassword(oncePasswordCreateParams, new IThingResultCallback<PasswordResp>() {
    @Override
    public void onSuccess(PasswordResp result) {
        //Created one-time offline password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
       //Failed to create one-time offline password
    }
});

Create a permanent online password

API description

ILockDevice # void createPermanentPassword(long siteId, String name, IThingResultCallback<PasswordResp> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
name The username for the password.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).createPermanentPassword(siteId, "permanent password", new IThingResultCallback<PasswordResp>() {
    @Override
    public void onSuccess(PasswordResp result) {
        //Create permanent password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to create permanent password
    }
});

When creating a permanent online password, the lock must be online.

Create a time-limited offline password

API description

ILockDevice # void createOfflinePassword(OfflinePasswordCreateParams params, IThingResultCallback<PasswordResp> callback);

Parameter description

Parameter Description
params The parameter bean for creating a time-limited offline password.
params.groupId The ID of the site to which the lock belongs.
params.deviceId The device ID.
params.passwordName The username for the password.
passwordType The password type, always set toPasswordType.TIME_LIMIT_OFFLINE.
params.effectiveTime The timestamp when the password becomes active, in milliseconds.
params.invalidTime The timestamp when the password expires, in milliseconds.
params.timeZoneId The time zone. If no value is specified, the SDK will assign one.
callback The callback.

Example

OfflinePasswordCreateParams params = new OfflinePasswordCreateParams();
params.groupId = siteId;
params.deviceId = deviceId;
params.passwordName = "Password Name";
params.effectiveTime = effectiveTime;
params.invalidTime = invalidTime;
params.passwordType = PasswordType.TIME_LIMIT_OFFLINE;
params.timeZoneId = ThingOSUser.getUserInstance().getUser().getTimezoneId();

ThingOSLock.newLockInstance(deviceId).createOfflinePassword(params, new IThingResultCallback<PasswordResp>() {
    @Override
    public void onSuccess(PasswordResp result) {
        //Created time-limited offline passwordd successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to create time-limited offline password
    }
});

Create a time-limited online password

API description

ILockDevice # void createLimitOnlinePassword(long siteId, String name, long effectiveTime, long invalidTime,
                                   String workingDay, String startMinuteFormat, String endMinuteFormat, IThingResultCallback<PasswordResp> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
name The name of the password.
params.effectiveTime The timestamp when the password becomes active, in milliseconds.
params.invalidTime The timestamp when the password expires, in milliseconds.
params.workingDay The schedule, a 7-bit string, with each bit being either 0 or 1.
0 indicates the schedule is off, while 1 indicates it is on.
The bits from left to right represent Sunday through Saturday.
params.startMinuteFormat The start time for access, a string in the format of hh:mm. For example, 03:30 indicates the e-key becomes active at 03:30.
params.endMinuteFormat The end time for access, a string in the format of hh:mm. For example, 18:30 indicates the e-key becomes inactive at 18:30.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).createLimitOnlinePassword(siteId, "Password Name",
effectiveTime, invalidTime, getWorkingDay(),
"03:30",
"19:50", new IThingResultCallback<PasswordResp>() {
    @Override
    public void onSuccess(PasswordResp result) {
        //Create time-limited online password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to create time-limited online password
    }
});

Delete a one-time offline password

API description

ILockDevice # void removeOnceOfflinePassword(long siteId, String passwordId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
passwordId The password ID.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).removeOnceOfflinePassword(siteId, passwordId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Removed one-time offline password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to remove one-time offline password
    }
});

Delete a permanent online password

API description

ILockDevice # void removeOnlinePassword(long siteId, String passwordId, String lockId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
passwordId The password ID.
lockId The virtual ID written to the lock device, which can be obtained from the password details.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).removeOnlinePassword(siteId, passwordId, passwordBean.lockId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Removed permanent online password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to remove permanent online password
    }
});

Delete a time-limited offline password

API description

ILockDevice # void removeLimitOfflinePassword(long siteId, String passwordId, IThingResultCallback<String> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
passwordId The password ID.
callback The callback. It returns a string of clear code. Users must manually enter the clear code on the lock to delete the respective time-limited offline password. Otherwise, the password will remain active.

Example

ThingOSLock.newLockInstance(deviceId).removeLimitOfflinePassword(siteId, passwordId, new IThingResultCallback<String>() {
    @Override
    public void onSuccess(String result) {
        //Removed time-limited offline password successfully
        //A clearing code is returned. Enter the clearing code in lock device
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to remove time-limited offline password
    }
});

Delete a time-limited online password

API description

ILockDevice # void removeOnlinePassword(long siteId, String passwordId, String lockId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
passwordId The password ID.
lockId The virtual ID written to the lock device, which can be obtained from the password details.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).removeOnlinePassword(siteId, passwordId, passwordBean.lockId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Removed time-limited online password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to remove time-limited online password
    }
});

Rename a password

API description

ILockDevice # void modifyPassword(PasswordUpdateParams params, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
params The parameter bean for renaming a password.
params.passwordId The password ID.
params.passwordName The name of the password.
params.deviceId The device ID.
params.groupId The site ID.
callback The callback.

Example

PasswordUpdateParams params = new PasswordUpdateParams();
params.deviceId = deviceId;
params.groupId = siteId;
params.passwordId = passwordId;
params.passwordName = "new name";
ThingOSLock.newLockInstance(deviceId).modifyPassword(params, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Modified password successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to modify password
    }
});