hivemq/hivemq-mqtt-client

Subscriber message,CONNECT failed as CONNACK contained an Error Code: BAD_USER_NAME_OR_PASSWORD

Opened this issue · 2 comments

image

1.3.0
hello. how to set username and password when i connect ?
with mqtt5 client

Hi @zqb666 - It depends on how the broker authorization is setup but for simple auth:

final Mqtt5BlockingClient client = Mqtt5Client.builder()
                        .identifier(getClientId())
                        .serverHost(HOST)
                        .serverPort(PORT)
                        .simpleAuth()
                            .username(USERNAME)
                            .password(ByteBuffer.wrap(PASSWORD.getBytes(StandardCharsets.UTF_8)))
                        .applySimpleAuth()

See also this blog post: Authentication with Username and Password

Hi @zqb666 - did this help out at all? Did you find a solution that works for you?