CRecordUserDbChangePassword
Change the password of a user in the user database.
This message belongs to the session manager API.
{
"id": "806fcf09-e60c-462f-ba50-3e99c579e74f",
"name": "USER_DB_CHANGE_PASSWORD ",
"description": "Change a password.",
"slots": [
{
"key": "user",
"name": "USER_ID",
"direction": "REQUEST",
"mandatory": "true",
"type": "STRING",
"description": "The id of the user."
},
{
"key": "currPw",
"name": "CURRENT_PASSWORD",
"direction": "REQUEST",
"mandatory": "true",
"type": "STRING",
"description": "The hashed base64 encoded current password."
},
{
"key": "newPw",
"name": "NEW_PASSWORD",
"direction": "REQUEST",
"mandatory": "true",
"type": "STRING",
"description": "The hashed base64 encoded new password."
}
]
}
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IIdSESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");
In addition to the user ID, the hash of the current password and that of the new password are required. Both SHA384 hashes must be base64 encoded. You can use a utility method of the kernel: CUtilPassword.hashPassword().
private void changePassword(@NotNull final String aUserId,
final char[] aCurrentPassword,
final char[] aNewPassword) throws CException
{
final String currentPasswordHash = CUtilPassword.hashPassword(aCurrentPassword);
final String newPasswordHash = CUtilPassword.hashPassword(aNewPassword);
final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID );
final CRecord record = CRecordUserDbChangePassword .create();
CRecordUserDbChangePassword .setUserId(record,
aUserId);
CRecordUserDbChangePassword .setCurrentPassword(record,
currentPasswordHash);
CRecordUserDbChangePassword .setNewPassword(record,
newPasswordHash);
sendRequest(env,
record);
}
Dealing with the response
To catch the response of the request, we need a message handler. We add it in the constructor of the message handler registry.
// constructor: addMessageHandler(CRecordUserDbChangePassword .ID, this::asyncChangePassword );
private booleanasyncChangePassword (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { // ... } return true; } return false; }