mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
Fix wrong password handling (string -> byte[])
This commit is contained in:
@@ -23,7 +23,7 @@ namespace MQTTnet.Tests
|
||||
var p = new MqttConnectPacket
|
||||
{
|
||||
ClientId = "XYZ",
|
||||
Password = "PASS",
|
||||
Password = Encoding.UTF8.GetBytes("PASS"),
|
||||
Username = "USER",
|
||||
KeepAlivePeriod = 123,
|
||||
CleanSession = true
|
||||
@@ -38,7 +38,7 @@ namespace MQTTnet.Tests
|
||||
var p = new MqttConnectPacket
|
||||
{
|
||||
ClientId = "XYZ",
|
||||
Password = "PASS",
|
||||
Password = Encoding.UTF8.GetBytes("PASS"),
|
||||
Username = "USER",
|
||||
KeepAlivePeriod = 123,
|
||||
CleanSession = true
|
||||
@@ -53,7 +53,7 @@ namespace MQTTnet.Tests
|
||||
var p = new MqttConnectPacket
|
||||
{
|
||||
ClientId = "XYZ",
|
||||
Password = "PASS",
|
||||
Password = Encoding.UTF8.GetBytes("PASS"),
|
||||
Username = "USER",
|
||||
KeepAlivePeriod = 123,
|
||||
CleanSession = true,
|
||||
@@ -75,7 +75,7 @@ namespace MQTTnet.Tests
|
||||
var p = new MqttConnectPacket
|
||||
{
|
||||
ClientId = "XYZ",
|
||||
Password = "PASS",
|
||||
Password = Encoding.UTF8.GetBytes("PASS"),
|
||||
Username = "USER",
|
||||
KeepAlivePeriod = 123,
|
||||
CleanSession = true
|
||||
@@ -90,7 +90,7 @@ namespace MQTTnet.Tests
|
||||
var p = new MqttConnectPacket
|
||||
{
|
||||
ClientId = "XYZ",
|
||||
Password = "PASS",
|
||||
Password = Encoding.UTF8.GetBytes("PASS"),
|
||||
Username = "USER",
|
||||
KeepAlivePeriod = 123,
|
||||
CleanSession = true,
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace MQTTnet.TestApp.NetCore
|
||||
|
||||
public class RandomPassword : IMqttClientCredentials
|
||||
{
|
||||
public string Password => Guid.NewGuid().ToString();
|
||||
public byte[] Password => Guid.NewGuid().ToByteArray();
|
||||
|
||||
public string Username => "the_static_user";
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
if (p.ClientId == "SpecialClient")
|
||||
{
|
||||
if (p.Username != "USER" || p.Password != "PASS")
|
||||
var password = Encoding.UTF8.GetString(p.Password);
|
||||
if (p.Username != "USER" || password != "PASS")
|
||||
{
|
||||
p.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
options.Credentials = new MqttClientCredentials
|
||||
{
|
||||
Username = User.Text,
|
||||
Password = Password.Text
|
||||
Password = Encoding.UTF8.GetBytes(Password.Text)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
//...
|
||||
}
|
||||
|
||||
client.UseApplicationMessageReceivedHandler(Handler);
|
||||
client.UseApplicationMessageReceivedHandler(e => Handler(e));
|
||||
|
||||
// Subscribe after connect
|
||||
|
||||
@@ -601,7 +601,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
Credentials = new MqttClientCredentials
|
||||
{
|
||||
Username = "bud",
|
||||
Password = "%spencer%"
|
||||
Password = Encoding.UTF8.GetBytes("%spencer%")
|
||||
},
|
||||
ChannelOptions = new MqttClientTcpOptions
|
||||
{
|
||||
@@ -633,7 +633,9 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Password != "mySecretPassword")
|
||||
var password = Encoding.UTF8.GetString(c.Password);
|
||||
|
||||
if (password != "mySecretPassword")
|
||||
{
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
@@ -717,7 +719,8 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.Password != "mySecretPassword")
|
||||
var password = Encoding.UTF8.GetString(c.Password);
|
||||
if (password != "mySecretPassword")
|
||||
{
|
||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user