Example #1
0
 private void LogInClick(object sender, RoutedEventArgs e)//opens program if valid login
 {
     try
     {
         if (canLogIn)
         {
             Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
             string loginUser = UsernameBox.Text;
             string loginPass = PasswordBoxBox.Password;
             int    passHash  = loginPass.GetHashCode();
             if (controller.CheckLoginInfo(loginUser, passHash))
             {
                 Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                 string  favTeam = controller.GetFavTeam(loginUser);
                 User    user    = new User(loginUser, passHash, favTeam);
                 Primary prim    = new Primary(user, controller);
                 prim.Show();
                 Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Username or Password is Incorrect!");
                 canLogIn = false;
                 DispatcherTimer timer = new DispatcherTimer();
                 timer.Interval = TimeSpan.FromSeconds(10);
                 timer.Tick    += timer_Tick;
                 timer.Start();
             }
         }
         else
         {
             MessageBox.Show("Incorrect Login Triggered 10 Second Delay!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Unable to sign in!");
         Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
     }
 }
 private void RegisterClick(object sender, RoutedEventArgs e)//validates password and existence of requested username
 {
     if (favTeamDropDown.SelectedIndex != 0)
     {
         string registerUser = UsernameBox.Text;
         string registerPass = PasswordBoxBox.Password;
         if (registerPass.Length >= 8)
         {
             if (registerPass.Any(char.IsDigit))
             {
                 int    passHash     = registerPass.GetHashCode();
                 string teamSelected = favTeamDropDown.SelectedValue.ToString();
                 if (controller.UserExists(registerUser) == false)
                 {
                     controller.AddUser(registerUser, passHash, teamSelected);
                     User    user = new User(registerUser, passHash, teamSelected);
                     Primary prim = new Primary(user, controller);
                     prim.Show();
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Username Already Exists!");
                 }
             }
             else
             {
                 MessageBox.Show("Password Does NOT Contain A Number!");
             }
         }
         else
         {
             MessageBox.Show("Password Must Be At Least 8 Characters!");
         }
     }
     else
     {
         MessageBox.Show("Favorite Team is Not Selected!");
     }
 }