Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Security.Cryptography;
- using System.IO;
- using System.Net;
- using System.Xml.Linq;
- using System.Xml;
- using System.Windows.Forms;
- namespace SG.Colonies
- {
- public class Colonies
- {
- public void loginConnection(string username, string password)
- {
- WebRequest req = WebRequest.Create(Server.loginAddress);
- req.Method = "POST";
- req.ContentType = "application/x-www-form-urlencoded";
- string postData = "username=" + username + "&password=" + password;
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- req.ContentLength = byteArray.Length;
- Stream ds = req.GetRequestStream();
- ds.Write(byteArray, 0, byteArray.Length);
- ds.Close();
- WebResponse wr = req.GetResponse();
- ds = wr.GetResponseStream();
- StreamReader reader = new StreamReader(ds);
- XDocument doc;
- try
- {
- string receive;
- doc = XDocument.Load(reader);
- receive = doc.ToString();
- User.logged = 1;
- if (User.logged == 1)
- {
- // mainUser.username = from c in doc.Descendants("root").Descendants("user") select c.Element("username");
- var q = from c in doc.Descendants("root").Descendants("user") select (string)c.Element("username");
- foreach (string name in q)
- User.username = name;
- q = from c in doc.Descendants("root").Descendants("user") select (string)c.Element("email");
- foreach (string email in q)
- User.email = email;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- public void regConn(string username, string password, string email, string planet)
- {
- WebRequest req = WebRequest.Create(Server.registerAddress);
- req.Method = "POST";
- req.ContentType = "application/x-www-form-urlencoded";
- string postData = "username=" + username + "&password=" + password +
- "&email=" + email + "&planet=" + planet;
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- req.ContentLength = byteArray.Length;
- Stream ds = req.GetRequestStream();
- ds.Write(byteArray, 0, byteArray.Length);
- ds.Close();
- WebResponse wr = req.GetResponse();
- //label1.Content = ((HttpWebResponse)wr).StatusDescription;
- ds = wr.GetResponseStream();
- StreamReader reader = new StreamReader(ds);
- XDocument doc;
- try
- {
- doc = XDocument.Load(reader);
- string receive;
- receive = doc.ToString();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- MessageBox.Show("Probably the username or email is already taken! Please try another one!", "Register Error", MessageBoxButtons.OK);
- }
- }
- public static string MD5Encrypt(string value)
- {
- string ret = String.Empty;
- MD5CryptoServiceProvider md5H = new MD5CryptoServiceProvider();
- byte[] data = System.Text.Encoding.ASCII.GetBytes(value);
- data = md5H.ComputeHash(data);
- for (int i = 0; i < data.Length; i++)
- {
- ret += data[i].ToString("x2").ToLower();
- }
- return ret;
- }
- }
- }
- /*
- public void xdoc(StreamReader read)
- {
- var q = from c in doc.Descendants("site") select (string)c.Element("name");
- foreach (string name in q)
- {
- username[i] = name;
- i++;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement