Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection refused: Bad username or password #1345

Closed
nicoworq opened this issue Oct 22, 2021 · 15 comments
Closed

Connection refused: Bad username or password #1345

nicoworq opened this issue Oct 22, 2021 · 15 comments

Comments

@nicoworq
Copy link

nicoworq commented Oct 22, 2021

Hi! I'm trying to connect to a Thingstream broker running MQTT 3.1.1, using user and pass.

  var username = "user";
  var pass = "pass";
 
  var client = mqtt.connect('mqtt:mqtt.thingstream.io',
    {   
      username: username,
      password: pass,
    }
  )

But I'm getting this error:

Error: Connection refused: Bad username or password
    at MqttClient._handleConnack (\mqttNode\node_modules\mqtt\lib\client.js:1190:15)
    at MqttClient._handlePacket (\mqttNode\node_modules\mqtt\lib\client.js:424:12)
    at work (\mqttNode\node_modules\mqtt\lib\client.js:321:12)
    at Writable.writable._write (\mqttNode\node_modules\mqtt\lib\client.js:335:5)
    at doWrite (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:409:139)
    at writeOrBuffer (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:398:5)
    at Writable.write (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:307:11)
    at Socket.ondata (internal/streams/readable.js:731:22)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12) {
  code: 4

I'm able to connect without problems using mosquitto client.

Any suggestion? Thanks in advance!

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 22, 2021 via email

@nicoworq
Copy link
Author

Nop, I'm able to connect without problems using mosquitto client.

@nicoworq
Copy link
Author

Is that the correct way to specify a user and password? Thanks!

@msalafia
Copy link

Probably because mosquitto_pub and mosquitto_sub bypass authentication on mosquitto. As i remember, there should be a root user called mosquitto that is always authorised on the mosquitto tools.

@odeliat
Copy link

odeliat commented Dec 16, 2021

Is there a solution for this issue? I'm getting the same error connecting to RabbitMQ.
I have 2 instances of the server, The first connected successfully but the second got this error.
How can I fix this?

const client = mqtt.connect(mqtt://hostname:1883, {
      username: "username",
      password: "password",
    });

@moeiscool
Copy link

moeiscool commented Jul 21, 2022

when i put username and password mqtt does not work anymore

|camera              | TypeError: Cannot read properties of undefined (reading 'resubscribe')
0|camera              |     at MqttClient.subscribe (/home/Shinobi/node_modules/mqtt/lib/client.js:701:27)
0|camera              |     at MqttClient.<anonymous> (/home/Shinobi/libs/notifications/mqtt.js:45:28)
0|camera              |     at MqttClient.emit (node:events:539:35)
0|camera              |     at Readable.<anonymous> (/home/Shinobi/node_modules/mqtt/lib/client.js:1863:14)
0|camera              |     at Readable.emit (node:events:527:28)
0|camera              |     at endReadableNT (/home/Shinobi/node_modules/readable-stream/lib/_stream_readable.js:1094:12)
0|camera              |     at processTicksAndRejections (node:internal/process/task_queues:83:21)

using command line client works fine with username and password

@robertsLando
Copy link
Member

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

@frank-niu-github
Copy link

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

I used the version 5.3.5 also have same issue.

@robertsLando
Copy link
Member

Can you connect using another client with same username/password?

@frank-niu-github
Copy link

Can you connect using another client with same username/password?

Yes. I successfully used the MQTTX tool and same username/password to connect to our MQTT server.

My vue3 source code as below:

image

@robertsLando
Copy link
Member

do you have a way to see what's coming to the broker? I would be curious to know what broker receives, I think it could be code/decode issue with the password/username, does they contain some strange char/symbol?

@frank-niu-github
Copy link

do you have a way to see what's coming to the broker? I would be curious to know what broker receives, I think it could be code/decode issue with the password/username, does they contain some strange char/symbol?

Hi RobertsLando, Thanks for you reply. Actually the username/password have ‘-’ symbol between the string word. How can I fixed this decode issue?

@robertsLando
Copy link
Member

Mine was just a supposition, the - doesn't have any decode issue. I suggest you to try checking what the broker receives

@frank-niu-github
Copy link

Mine was just a supposition, the - doesn't have any decode issue. I suggest you to try checking what the broker receives

Thanks for your suggestions. This is my fault. Because our MQTT broker setting the HTTP auth. The backend of the cloud server is responsible for verifying the username/password send by Websocket. Always return bad username/password when there is no response from the backend.

@robertsLando
Copy link
Member

robertsLando commented Feb 2, 2024

Closing this for now as I have a feel that when this happens it's most likely a user issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants