Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Password change issue in AEM

rahul_kumar11
Level 3
Level 3

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.

1 Reply
smacdonald2008
Level 10
Level 10

Can you post the Exception message please.