Exemplo n.º 1
0
 /// <summary>
 /// On click, sends username,password, and IP to createUser function
 /// Also checks validity of username and password
 ///     i.e. Can't be blank, must contain letters and numbers only, and username can't already exist
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void newUserButton_Click(object sender, EventArgs e)
 {
     errorLabel.Hide();
     //Check that the inputs are not empty
     if (newUsername.TextLength > 0 && newPassword.TextLength > 0)
     {
         if (ContainsVaildChars(newUsername.Text) && ContainsVaildChars(newPassword.Text))
         {
             var good = NetworkClasses.CreateUser(newUsername.Lines[0], newPassword.Lines[0],
                                                  Helpers.GetLocalIpAddress());
             if (good)
             {
                 Form form = new LoginForm();
                 form.Show();
                 Dispose();
             }
             else
             {
                 errorLabel.Text = "Username already exists.";
                 errorLabel.Show();
             }
         }
         else
         {
             errorLabel.Text = "LETTERS AND NUMBERS ONLY";
             errorLabel.Show();
         }
     }
     else
     {
         errorLabel.Text = "Username/Password cannot be blank.";
         errorLabel.Show();
     }
 }
 /// <summary>
 /// Checks validity of username and password and sends info to database
 ///     i.e. Length must be between 1 and 20, must contain letters and numbers only, and username can't already exist
 /// </summary>
 private void Create()
 {
     //Check that the inputs are not empty
     if (newUsername.TextLength > 0 && newPassword.TextLength >= 5 && newUsername.TextLength <= 20 && newPassword.TextLength < 20)
     {
         if (ContainsVaildChars(newUsername.Text) && ContainsVaildChars(newPassword.Text))
         {
             var good = NetworkClasses.CreateUser(newUsername.Lines[0], newPassword.Lines[0],
                                                  Helpers.GetLocalIpAddress());
             if (good)
             {
                 Form form = new LoginForm();
                 form.Show();
                 Dispose();
             }
             else
             {
                 MessageBox.Show("Username already exists.", "Error", MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
             }
         }
         else
         {
             MessageBox.Show("LETTERS AND NUMBERS ONLY", "Error", MessageBoxButtons.OK,
                             MessageBoxIcon.Exclamation);
         }
     }
     else
     {
         if (newUsername.Text.Length < 1 || newUsername.Text.Length > 20)
         {
             MessageBox.Show(
                 "Username must be between 1 and 20 characters",
                 "Error", MessageBoxButtons.OK,
                 MessageBoxIcon.Exclamation);
         }
         if (newPassword.Text.Length < 5 || newPassword.Text.Length < 20)
         {
             MessageBox.Show(
                 "Password must be between 5 and 20 characters",
                 "Error", MessageBoxButtons.OK,
                 MessageBoxIcon.Exclamation);
         }
     }
 }