public string GetPublicKey() { AccountCreation ac = new AccountCreation(); ac.pubKey = Encryption.GetPubKey(); ac.message = new byte[0]; return ac.ToString(); }
public static bool CreateAccount(string userName, string password) { AccountCreation ac; try { string wrURI = baseServerTarget + "getpublickey"; WebRequest wreq = WebRequest.Create(wrURI); WebResponse wresp = wreq.GetResponse(); using (StreamReader sr = new StreamReader(wresp.GetResponseStream())) { XmlSerializer rsa = new XmlSerializer(typeof(string), StringNamespace); string resp = (string)rsa.Deserialize(sr); ac = new AccountCreation(resp); } } catch { return false; } // Not meant as encryption, but at least makes sure that the text we // save on the server isn't an actual password. password = Encryption.GetSha256Hash(password); ac.message = Encryption.Encrypt(String.Format("{0}\n{1}", userName, password), ac.pubKey); try { string wrURI = baseServerTarget + "createaccount"; string msg = ac.ToString(); WebRequest wreq = WebRequest.Create(wrURI + "?message=" + msg); wreq.Method = "POST"; wreq.ContentLength = 0; WebResponse wresp = wreq.GetResponse(); using (TextReader sr = new StreamReader(wresp.GetResponseStream())) { XmlSerializer xml = new XmlSerializer(typeof(bool), StringNamespace); bool resp = (bool)xml.Deserialize(sr); return resp; } } catch { return false; } }
public bool CreateAccount(string message) { AccountCreation ac = new AccountCreation(message); try { string decMessage = Encryption.Decrypt(ac.message, ac.pubKey); char[] split = new char[] { '\n' }; string[] credentials = decMessage.Split(split, 2); // If the account already exists, don't make a new one. if(Account.LoadAccount(credentials[0]) != null) { return false; } // otherwise make a new one. if (new Account(credentials[0], credentials[1]) != null) { return true; } } catch {} return false; }