From 840ec4a64d8f23739ead8591d7fd05fdea30d93f Mon Sep 17 00:00:00 2001 From: icedream Date: Wed, 7 May 2014 22:00:34 +0200 Subject: [PATCH] Fixing AuthenticationHelper fuckups (regex/http verb) --- src/libnpsharp/Authentication/AuthenticationHelper.cs | 10 +++++----- src/npmotd/Program.cs | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libnpsharp/Authentication/AuthenticationHelper.cs b/src/libnpsharp/Authentication/AuthenticationHelper.cs index 5d48b69..95c0fb7 100644 --- a/src/libnpsharp/Authentication/AuthenticationHelper.cs +++ b/src/libnpsharp/Authentication/AuthenticationHelper.cs @@ -65,19 +65,19 @@ namespace NPSharp.Authentication Path = _path }.Uri; - var req = (HttpWebRequest)WebRequest.Create (uri); + var req = (HttpWebRequest)WebRequest.Create(uri); + req.Method = "POST"; + req.ContentType = "application/x-www-form-urlencoded"; + req.AllowAutoRedirect = true; using (var reqStream = req.GetRequestStream()) { var buffer = Encoding.UTF8.GetBytes (post); reqStream.Write (buffer, 0, post.Length); reqStream.Flush (); } - req.Method = "POST"; - //req.ContentType = "application/x-www-urlencodedform"; - req.AllowAutoRedirect = true; // Response will be in this syntax: // (ok|fail)#text#userid#username#email#sessiontoken - var rx = new Regex ("^(?Pok|fail)#(?P.+)#(?P[0-9]+)#(?P.+)#(?P.+)#(?P.+)$"); + var rx = new Regex("^(?ok|fail)#(?.+)#(?[0-9]+)#(?.+)#(?.+)#(?.+)$"); var resp = (HttpWebResponse)req.GetResponse (); using (var respStream = resp.GetResponseStream()) { using (var respReader = new StreamReader(respStream)) { diff --git a/src/npmotd/Program.cs b/src/npmotd/Program.cs index b66d988..ac3de4f 100644 --- a/src/npmotd/Program.cs +++ b/src/npmotd/Program.cs @@ -17,9 +17,13 @@ namespace NPSharp.CommandLine.MOTD { ah.Authenticate(username, password); } - catch + catch (Exception err) { - Console.Error.WriteLine("Could not authenticate."); +#if DEBUG + Console.Error.WriteLine("Could not authenticate: {0}", err); +#else + Console.Error.WriteLine("Could not authenticate: {0}", err.Message); +#endif return; }