/// <summary> /// Saves a username and password combination to the authentication list. /// </summary> /// <param name="username">The username to add.</param> /// <param name="password">The password to add.</param> /// <param name="saveData">True if the data has to be written to the XML file, false otherwise.</param> /// <exception cref="ArgumentNullException"><c>username</c> is null -or- <c>password</c> is null.</exception> /// <exception cref="ArgumentException">The specified username is invalid.</exception> /// <remarks><p>If the user already exists in the collection, the old password will be changed to the new one.</p><p>The username 'users' is invalid because it is used internally to store the usernames.</p><p>The password will be hashed before it is stored in the authentication list.</p></remarks> public void SaveUserPass(string username, string password, bool saveData) { if (username == null || password == null) { throw new ArgumentNullException(); } if (username.ToLower() == "users" || username == "") { throw new ArgumentException(); } if (UserList.IsUserPresent(username)) { UserList.RemoveItem(username); } UserList.AddItem(username, password); if (saveData) { SaveData(); } }
private void LoadListeners() { string oldip = IP; string oldHttpPort = httpport.ToString(); string oldSocksPort = sock5port.ToString(); IP = GetIP(); if (IP == string.Empty) { return; } int[] arr = getRandomNum(2, 10000, 30000); httpport = arr[0]; sock5port = arr[1]; RegisterEntiy entity = new RegisterEntiy(); // HTTP代理 Listener listener = null; listener = CreateListener("xProxy.Http.HttpListener", string.Format("host:{0};int:{1}", IP, httpport)); if (listener != null) { try { listener.Start(); AddListener(listener); entity.Ip = IP; entity.HttpPort = httpport; entity.SocketPort = 0; } catch (Exception e) { Console.WriteLine("HTTP代理启动失败!" + e.Message); } } //socks5 代理 UserList.Clear(); string Name = GetRandomStr(); string Pwd = getRandomNum(1, 1000, 10000)[0].ToString(); UserList.AddItem(Name, Pwd); listener = CreateListener("xProxy.Socks.SocksListener", string.Format("host:{0};int:{1};authlist", IP, sock5port)); if (listener != null) { try { listener.Start(); AddListener(listener); entity.Ip = IP; entity.SocketPort = sock5port; entity.UName = Name; entity.UPwd = Pwd; } catch (Exception e) { Console.WriteLine("SOCKS5代理启动失败!" + e.Message); } } if (entity.Ip != null) { try { if (!service.RegisterProxy(entity)) { Console.WriteLine("向服务器注册代理失败!请重试!"); } else { Console.WriteLine("向服务器注册代理成功!"); } } catch (Exception e) { Console.WriteLine("注册代理失败:" + e.Message); } } }
private void btnRegister_Click(object sender, EventArgs e) { if (!txtPassword_2.Text.ToString().Equals(txtPassword.Text.ToString())) { MessageBox.Show("Error: Passwords dont match"); return; } try { User myUser = new User(); myUser.Email = txtEmail.Text; myUser.CostPerGame = 1.0; myUser.Balance = 50; myUser.Password = txtPassword.Text; myUser.UserName = txtUsername.Text; myUser.ImageURL = Helper.GetImageDirectory() + "\\" + txtImage.Text; UserList myUserList = new UserList(); XMLHelper<UserList> myXML = new XMLHelper<UserList>(); myXML.Load(ref myUserList); if(myUserList.FindName(myUser.UserName) == -1) { myUserList.AddItem(myUser); myXML.Save(myUserList); this.Dispose(); if (WriteInHome != null) WriteInHome(); } else { MessageBox.Show("This Username has been Taken, Please Select Another Name"); } } catch (Exception ex) { MessageBox.Show("Error Occurred: " + ex.Message.ToString()); return; } }
private void btnUpdate_Click(object sender, EventArgs e) { if (!txtPassword_2.Text.ToString().Equals(txtPassword.Text.ToString())) { MessageBox.Show("Error: Passwords dont match"); return; } try { User myUser = new User(); myUser.Email = txtEmail.Text; myUser.ImageURL = SelectedImageURL; myUser.Password = txtPassword.Text; myUser.IsApproved = true; myUser.UserName = txtUsername.Text; myUser.ImageURL = txtImage.Text; UserList myUserList = new UserList(); XMLHelper<UserList> myXML = new XMLHelper<UserList>(); myXML.Load(ref myUserList); int Index = myUserList.FindName(myUser.UserName); if (Index != -1) { myUserList.RemoveItem(Index); myUserList.AddItem(myUser); myXML.Save(myUserList); this.Dispose(); } else { MessageBox.Show("Error: This username does not exist"); } } catch (Exception ex) { MessageBox.Show("Error Occurred: " + ex.Message.ToString()); return; } }