mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix special chars in minecraft passwords
Bug report by TNT-UP
This commit is contained in:
parent
850ff7ad0b
commit
84ba8fd0ae
1 changed files with 26 additions and 1 deletions
|
|
@ -100,7 +100,7 @@ namespace MinecraftClient.Protocol
|
|||
try
|
||||
{
|
||||
string result = "";
|
||||
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + user + "\", \"password\": \"" + pass + "\" }";
|
||||
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + jsonEncode(user) + "\", \"password\": \"" + jsonEncode(pass) + "\" }";
|
||||
int code = doHTTPSPost("authserver.mojang.com", "/authenticate", json_request, ref result);
|
||||
if (code == 200)
|
||||
{
|
||||
|
|
@ -204,5 +204,30 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
else return 520; //Web server is returning an unknown error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode a string to a json string.
|
||||
/// Will convert special chars to \u0000 unicode escape sequences.
|
||||
/// </summary>
|
||||
/// <param name="text">Source text</param>
|
||||
/// <returns>Encoded text</returns>
|
||||
|
||||
private static string jsonEncode(string text)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
foreach (char c in text)
|
||||
{
|
||||
if (char.IsLetterOrDigit(c))
|
||||
{
|
||||
result.Append(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Append("\\u");
|
||||
result.Append(((int)c).ToString("x4"));
|
||||
}
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue