Hi i got requirement to change password of user profile .
Able to change user password in cq 5.6.1 but while coming to AEM 6.0 getting an error.
I have used below code.
private boolean checkPassword(Authorizable authorizable, String oldPassword) {
Class<?> oldCredsClass = null;
try {
Credentials oldCreds = ((User) authorizable).getCredentials();
if (oldCreds instanceof SimpleCredentials) {
char[] oldCredsPwd = ((SimpleCredentials) oldCreds).getPassword();
if (oldPassword.equals(String.valueOf(oldCredsPwd))) {
return Boolean.TRUE;
}
} else {
// CryptSimpleCredentials.matches(SimpleCredentials credentials)
oldCredsClass = oldCreds.getClass();
Method matcher = oldCredsClass.getMethod("matches", SimpleCredentials.class);
SimpleCredentials newCreds = new SimpleCredentials(authorizable
.getPrincipal().getName(), oldPassword.toCharArray());
boolean match = (Boolean) matcher.invoke(oldCreds, newCreds);
if (match) {
return Boolean.TRUE;
}
}
}
catch (Exception t) {
log.info(" Catch block " + t.getClass() );
return Boolean.FALSE;
}
log.info(" Not executing any block And the class type1 " + oldCredsClass );
return Boolean.FALSE;
}
That would be great helpful.
Thanks,
Rahul.