public static void login(Data ircdata, bool wget) { string line; string name; if (ircdata.MessageEx.Count() > 1) { name = ircdata.MessageEx[1]; } else { name = ircdata.Nick; } StreamReader file = new StreamReader("accounts.txt"); while ((line = file.ReadLine()) != null) { string[] args = line.Split(' '); if (args[0] == name) { gpg.Recipient = args[1]; MemoryStream unencrypted = new MemoryStream(Encoding.ASCII.GetBytes(args[0] + ":" + DateTime.Now.Ticks + "\n")); MemoryStream encrypted = new MemoryStream(); gpg.Encrypt(unencrypted, encrypted); Pastie p = new Pastie(); string pastie = p.SendViaPasteBin(StreamToString(encrypted), "#bitcoin-police gpg login request for: " + name); string[] paste = pastie.Split('/'); if (wget) { irc.Message(SendType.Message, ircdata.Channel, ircdata.Nick + ": wget -qO http://pastebin.com/raw.php?i=" + paste[3] + " | gpg --decrypt"); } else { irc.Message(SendType.Message, ircdata.Channel, ircdata.Nick + ": Request here: http://pastebin.com/raw.php?i=" + paste[3]); } System.IO.StreamWriter sw = new StreamWriter(name + "_challenge.txt"); sw.WriteLine(StreamToString(unencrypted)); sw.Close(); } } file.Close(); }
/// <summary> /// Login As a registered User. /// This is the first step in a two step login and returns a nonce (One-Time code) fo rthe user to decrypt with their known key. /// </summary> /// <param name="n"></param> /// <param name="e"></param> /// <param name="wget"></param> protected void login(Network n, Irc.IrcEventArgs e, bool wget) { string name = ""; if (IsMatch("^.?eauth (?<name>.*?)$", e.Data.Message.Substring(BOT_CONTROL_SEQ.Length))) { name = (Matches["name"].Value.Length > 16) ? Matches["name"].Value.Substring(0, 16) : Matches["name"].Value; } else { name = e.Data.Nick; } System.Data.DataTable accounts; String query = "SELECT id \"ID\", name \"NAME\", email \"EMAIL\", gpgkey \"key\" FROM accounts;"; accounts = db.GetDataTable(query); int id = 0; foreach (DataRow account in accounts.Rows) { id++; if (account["NAME"] as string == name) { gpg.Recipient = account["key"] as string; MemoryStream unencrypted = new MemoryStream(Encoding.ASCII.GetBytes(name + ":" + DateTime.Now.Ticks + "\n")); MemoryStream encrypted = new MemoryStream(); gpg.Encrypt(unencrypted, encrypted); Dictionary<String, String> data = new Dictionary<String, String>(); data.Add("verify", StreamToString(unencrypted)); db.Update("accounts", data, String.Format("id = {0}", id)); Pastie p = new Pastie(); string pastie = p.SendViaPasteBin(StreamToString(encrypted), "#bitcoin-police gpg login request for: " + name); string[] paste = pastie.Split('/'); if (wget) { Answer(n, e, e.Data.Nick + ": wget -qO " + FormatBold("http://pastebin.com/raw.php?i=" + paste[3]) + " | gpg --decrypt"); } else { Answer(n, e, e.Data.Nick + ": Request here: "+ FormatBold("http://pastebin.com/raw.php?i=" + paste[3])); } } } }