BF2Statistics.Database.GamespyDatabase.CreateUser C# (CSharp) Method

CreateUser() public method

Creates a new Gamespy Account
Only used in the Gamespy Account Creation Form
public CreateUser ( int Pid, string Nick, string Pass, string Email, string Country ) : bool
Pid int The Profile Id to assign this account
Nick string The Account Name
Pass string The UN-HASHED Account Password
Email string The Account Email Address
Country string The Country Code for this Account
return bool
        public bool CreateUser(int Pid, string Nick, string Pass, string Email, string Country)
        {
            // Make sure the user doesnt exist!
            if (UserExists(Pid))
                throw new Exception("Account ID is already taken!");
            else if(UserExists(Nick))
                throw new Exception("Account username is already taken!");

            // Create the user in the database
            int Rows = base.Execute("INSERT INTO accounts(id, name, password, email, country) VALUES(@P0, @P1, @P2, @P3, @P4)",
                Pid, Nick, Pass.GetMD5Hash(false), Email.ToLowerInvariant(), Country
            );

            return (Rows != 0);
        }

Same methods

GamespyDatabase::CreateUser ( string Nick, string Pass, string Email, string Country ) : int

Usage Example

        private void CreateBtn_Click(object sender, EventArgs e)
        {
            int Pid = (int)PidBox.Value;

            using (GamespyDatabase Database = new GamespyDatabase())
            {
                // Make sure there is no empty fields!
                if (AccountName.Text.Trim().Length < 3)
                {
                    MessageBox.Show("Please enter a valid account name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (AccountPass.Text.Trim().Length < 3)
                {
                    MessageBox.Show("Please enter a valid account password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (!Validator.IsValidEmail(AccountEmail.Text))
                {
                    MessageBox.Show("Please enter a valid account email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Check if PID exists (for changing PID)
                if (PidSelect.SelectedIndex == 1)
                {
                    if (!Validator.IsValidPID(Pid.ToString()))
                    {
                        MessageBox.Show("Invalid PID Format. A PID must be 8 or 9 digits in length", "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else if (Database.UserExists(Pid))
                    {
                        MessageBox.Show("PID is already in use. Please enter a different PID.", "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                // Check if the user exists
                if (Database.UserExists(AccountName.Text))
                {
                    MessageBox.Show("Account name is already in use. Please select a different Account Name.", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                try
                {
                    // Attempt to create the account
                    if (PidSelect.SelectedIndex == 1)
                        Database.CreateUser(Pid, AccountName.Text, AccountPass.Text, AccountEmail.Text, "00");
                    else
                        Database.CreateUser(AccountName.Text, AccountPass.Text, AccountEmail.Text, "00");

                    Notify.Show("Account Created Successfully!", AccountName.Text, AlertType.Success);
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message, "Account Create Error");
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
All Usage Examples Of BF2Statistics.Database.GamespyDatabase::CreateUser