public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"jabber:iq:auth\">"); if (username != null) { if (username.equals("")) { buf.append("<username/>"); } else { buf.append("<username>").append(username).append("</username>"); } } if (digest != null) { if (digest.equals("")) { buf.append("<digest/>"); } else { buf.append("<digest>").append(digest).append("</digest>"); } } if (password != null && digest == null) { if (password.equals("")) { buf.append("<password/>"); } else { buf.append("<password>").append(StringUtils.escapeForXML(password)).append("</password>"); } } if (resource != null) { if (resource.equals("")) { buf.append("<resource/>"); } else { buf.append("<resource>").append(resource).append("</resource>"); } } buf.append("</query>"); return buf.toString(); }
/** * Sets the digest value using a connection ID and password. Password digests offer a more secure * alternative for authentication compared to plain text. The digest is the hex-encoded SHA-1 hash * of the connection ID plus the user's password. If the digest and password are set, digest * authentication will be used. If only one value is set, the respective authentication mode will * be used. * * @param connectionID the connection ID. * @param password the password. * @see z.org.jivesoftware.smack.Connection#getConnectionID() */ public void setDigest(String connectionID, String password) { this.digest = StringUtils.hash(connectionID + password); }