protected Map<String, Object> convertProfileAndPasswordToAttributes(final U profile, final String password) {
        Map<String, Object> storageAttributes = new HashMap<>();
        storageAttributes.put(getIdAttribute(), profile.getId());
        storageAttributes.put(LINKEDID, profile.getLinkedId());
        storageAttributes.put(getUsernameAttribute(), profile.getUsername());
        // if a password has been provided, encode it
        if (StringUtils.isNotBlank(password)) {
            final String encodedPassword;
            // encode password if we have a passwordEncoder (MongoDB, SQL but not for LDAP)
            if (passwordEncoder != null) {
                encodedPassword = passwordEncoder.encode(password);
            } else {
                encodedPassword = password;
            }
            storageAttributes.put(getPasswordAttribute(), encodedPassword);
        }
        // legacy mode: save the defined attributes
        if (isLegacyMode()) {
            for (val attributeName : attributeNames) {
                storageAttributes.put(attributeName, profile.getAttribute(attributeName));
            }
        } else {
            // new behaviour (>= v2.0): save the serialized profile
            storageAttributes.put(SERIALIZED_PROFILE, serializer.serializeToString(profile));
        }
        return storageAttributes;
    }
Convert a profile and a password into a map of attributes for the storage.

@param profile the profile
@param password the password
@return the attributes
pac4j-core/src/main/java/org/pac4j/core/profile/service/AbstractProfileService.java