1

I'm trying to design a plugin for a game, and the software is built on .Net 3.5.

The code I'm trying to implement is:

public bool LoginToLee(string user, string pass, bool remember = false) { string res = Net.GetResponse("http://leeizazombie.com/member.php?action=login", new Dictionary<string, string>() { { "username", username }, { "password", password }, { "remember", (remember ? "yes" : "no") }, { "action", "do_login" }, { "url", "" } }); return !res.Contains("You have entered an invalid username/password combination. "); } 

The error I get is "Default parameter specifiers are not permitted"

I'm well aware that this error won't happen if I was compiling the plugin with .Net 4.0, but unfortunately I can't support the plugin on the .Net 3.5 program then.

So I was wondering if it was possible to work around this in any way?

Oh and by the way, if it's necessary to see what the "Net.GetResponse" is part of, here's the code:

namespace NetUtils { public class Net { public static bool IsUrl(object obj) { try { new Uri(obj.ToString()); return true; } catch { return false; } } private static string Data2Post(Dictionary<string, string> data) { string postData = ""; foreach (KeyValuePair<string, string> k in data) { if (postData != "") { postData += '&'; } postData = postData + k.Key + "=" + k.Value; } return postData; } public static string GetResponse(string url, byte[] data) { if (!IsUrl(url)) { return "Invalid url."; } return GetResponseInternal(new Uri(url), data); } public static string GetResponse(string url, Dictionary<string, string> data) { if (!IsUrl(url)) { return "Invalid url."; } return GetResponse(new Uri(url), Data2Post(data)); } public static string GetResponse(string url, string data) { if (!IsUrl(url)) { return "Invalid url."; } return GetResponse(new Uri(url), data); } public static string GetResponse(Uri url, Dictionary<string, string> data) { return GetResponse(url, Data2Post(data)); } public static string GetResponse(Uri url, string data) { return GetResponseInternal(url, new UTF8Encoding().GetBytes(data)); } public static string GetResponse(Uri url, byte[] data) { return GetResponseInternal(url, data); } private static string GetResponseInternal(Uri url, byte[] data) { HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); httpWReq.Method = "POST"; httpWReq.ContentType = "application/x-www-form-urlencoded"; httpWReq.ContentLength = data.Length; using (Stream stream = httpWReq.GetRequestStream()) { stream.Write(data, 0, data.Length); } HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse(); string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); return responseString; } } } 
0

1 Answer 1

3

So I was wondering if it was possible to work around this in any way?

Yes, make an overload:

public bool LoginToLee(string user, string pass) { return LoginToLee(user, pass, false); } public bool LoginToLee(string user, string pass, bool remember) { string res = Net.GetResponse("http://leeizazombie.com/member.php?action=login", new Dictionary<string, string>() { { "username", username }, { "password", password }, { "remember", (remember ? "yes" : "no") }, { "action", "do_login" }, { "url", "" } }); return !res.Contains("You have entered an invalid username/password combination. "); } 

Also, you shouldn't be sending passwords in plaintext over HTTP.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I'll try it out, and this is only testing out the authentication

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.