Exemple #1
0
        public override void HandlePost(HttpListenerContext ctx, WebUser user, string postData)
        {
            WebUserApiParams p = null;

            if ((p = TryJsonParse <WebUserApiParams>(ctx, postData)) == null)
            {
                return;
            }

            switch (p.Action)
            {
            case "users_get":
                break;

            case "users_create":
                WebServer.LogAudit(user, "created user {0}", p.Username);
                Core.Database.InsertWebUser(new WebUser(p.Username, PBKDF2.HashPassword(Util.Md5(p.SpaceInvaders))));
                break;

            case "users_edit":
                WebServer.LogAudit(user, "modified user {0}", p.Username);
                Core.Database.UpdateWebUser(new WebUser(p.Id, p.Username, PBKDF2.HashPassword(Util.Md5(p.SpaceInvaders))), p.UpdateSpaceInvaders);
                break;

            case "users_delete":
                WebServer.LogAudit(user, "deleted user {0}", p.Username);
                Core.Database.DeleteWebUser(new WebUser(p.Id));
                break;
            }

            WebAdmin.SendHtml(ctx, ToJson(Core.Database.GetWebUsers()));
        }
        private async void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            string username = TxtUsername.Text;

            if (username.Length >= 4 && await GameState.CheckNewPlayerName(username) && PswdPassword.Password == PswdConfirmPassword.Password && PswdPassword.Password.Length >= 4)
            {
                string hashedPassword = PBKDF2.HashPassword(PswdPassword.Password);
                Player newPlayer      = new Player(username, hashedPassword, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, new List <Achievement>());
                if (await GameState.NewPlayer(newPlayer))
                {
                    GameState.CurrentPlayer = new Player(newPlayer);
                    GameState.Navigate(new GameOptionsPage {
                        NewPlayer = true
                    });
                }
            }
            else if (username.Length < 4)
            {
                GameState.DisplayNotification("Usernames must be at least 4 characters in length.", "Math Game");
            }
            else if (PswdPassword.Password != PswdConfirmPassword.Password)
            {
                GameState.DisplayNotification("Please ensure that the entered passwords match.", "Math Game");
            }
            else if (PswdPassword.Password.Length < 4)
            {
                GameState.DisplayNotification("Passwords must be at least 4 characters in length.", "Math Game");
            }
            else
            {
                GameState.DisplayNotification("That username is already taken.", "Math Game");
            }
        }
Exemple #3
0
        /// <summary>Modifies a <see cref="User"/> in the database.</summary>
        private async Task ModifyUser()
        {
            AppState.CurrentUser.Username  = TxtUsername.Text.Trim();
            AppState.CurrentUser.FirstName = TxtFirstName.Text.Trim();
            AppState.CurrentUser.LastName  = TxtLastName.Text.Trim();
            AppState.CurrentUser.Password  = PswdPassword.Password.Length >= 4 ? PBKDF2.HashPassword(PswdPassword.Password.Trim()) : AppState.CurrentUser.Password;

            if (AppState.CurrentUser != OriginalUser)
            {
                if (AppState.CurrentUser.Roles.ToList().Count > 0)
                {
                    if (await AppState.ChangeUserDetails(OriginalUser, AppState.CurrentUser).ConfigureAwait(false))
                    {
                        Dispatcher.Invoke(() => AppState.GoBack());
                    }
                }
                else
                {
                    AppState.DisplayNotification("There are no roles assigned to this User.", "Time Clock");
                }
            }
            else
            {
                AppState.DisplayNotification("There are no changes to save.", "Time Clock");
            }
        }
        public void Hashing()
        {
            const string password = "******";

            var hash   = PBKDF2.HashPassword(password);
            var result = PBKDF2.Verify(hash, password);

            result.Should().BeTrue();
        }
 private async void BtnSubmit_Click(object sender, RoutedEventArgs e)
 {
     if (PswdNewPassword.Password.Length >= 4 && PswdConfirmPassword.Password.Length >= 4)
     {
         if (PswdNewPassword.Password == PswdConfirmPassword.Password)
         {
             if (PswdCurrentPassword.Password != PswdNewPassword.Password)
             {
                 if (!_blnAdmin)
                 {
                     if (PBKDF2.ValidatePassword(PswdCurrentPassword.Password, GameState.CurrentUser.Password))
                     {
                         GameState.CurrentUser.Password = PBKDF2.HashPassword(PswdNewPassword.Password);
                         if (await GameState.ChangeUserDetails(GameState.CurrentUser, GameState.CurrentUser))
                         {
                             GameState.DisplayNotification("Successfully changed password.", "Assassin");
                             ClosePage();
                         }
                     }
                     else
                     {
                         GameState.DisplayNotification("Invalid current password.", "Assassin");
                     }
                 }
                 else
                 {
                     if (PBKDF2.ValidatePassword(PswdCurrentPassword.Password, GameState.AdminPassword))
                     {
                         GameState.AdminPassword = PBKDF2.HashPassword(PswdNewPassword.Password);
                         if (await GameState.DatabaseInteraction.ChangeAdminPassword(GameState.AdminPassword))
                         {
                             GameState.DisplayNotification("Successfully changed admin password.", "Assassin");
                             ClosePage();
                         }
                     }
                     else
                     {
                         GameState.DisplayNotification("Invalid current password.", "Assassin");
                     }
                 }
             }
             else
             {
                 GameState.DisplayNotification("The new password can't be the same as the current password.", "Assassin");
             }
         }
         else
         {
             GameState.DisplayNotification("Please ensure the new passwords match.", "Assassin");
         }
     }
     else
     {
         GameState.DisplayNotification("Your password must be at least 4 characters.", "Assassin");
     }
 }
        /// <summary>Assigns all the Controls' data to the _selectedUser <see cref="User"/>.</summary>
        private void AssignSelectedUser(bool hashPassword = false)
        {
            _selectedUser.Name = TxtName.Text.Trim();
            if (hashPassword)
            {
                _selectedUser.Password = PBKDF2.HashPassword(PswdPassword.Password.Trim());
            }

            // character
            _selectedUser.Level            = Int32Helper.Parse(TxtLevel.Text.Trim());
            _selectedUser.Experience       = Int32Helper.Parse(TxtExperience.Text.Trim());
            _selectedUser.SkillPoints      = Int32Helper.Parse(TxtSkillPoints.Text.Trim());
            _selectedUser.Alive            = ChkAlive.IsChecked != null && ChkAlive.IsChecked.Value;
            _selectedUser.CurrentEndurance = Int32Helper.Parse(TxtCurrentEndurance.Text.Trim());
            _selectedUser.CurrentLocation  = EnumHelper.Parse <SleepLocation>(CmbLocation.SelectedItem.ToString());
            _selectedUser.MaximumEndurance = Int32Helper.Parse(TxtMaximumEndurance.Text.Trim());
            _selectedUser.Hunger           = Int32Helper.Parse(TxtHunger.Text.Trim());
            _selectedUser.Thirst           = Int32Helper.Parse(TxtThirst.Text.Trim());

            // inventory
            _selectedUser.CurrentWeaponType = EnumHelper.Parse <WeaponType>(CmbCurrentWeapon.SelectedItem.ToString());
            _selectedUser.LightWeapon       = (Weapon)CmbLightWeapon.SelectedItem;
            _selectedUser.HeavyWeapon       = (Weapon)CmbHeavyWeapon.SelectedItem;
            _selectedUser.TwoHandedWeapon   = (Weapon)CmbTwoHWeapon.SelectedItem;
            _selectedUser.Armor             = (Armor)CmbArmor.SelectedItem;
            _selectedUser.Potion            = (Potion)CmbPotion.SelectedItem;
            _selectedUser.Lockpicks         = Int32Helper.Parse(TxtLockpicks.Text.Trim());
            _selectedUser.GoldOnHand        = Int32Helper.Parse(TxtGoldOnHand.Text.Trim());
            _selectedUser.GoldInBank        = Int32Helper.Parse(TxtGoldInBank.Text.Trim());
            _selectedUser.GoldOnLoan        = Int32Helper.Parse(TxtGoldOnLoan.Text.Trim());
            _selectedUser.Shovel            = ChkShovel.IsChecked != null && ChkShovel.IsChecked.Value;
            _selectedUser.Lantern           = ChkLantern.IsChecked != null && ChkLantern.IsChecked.Value;
            _selectedUser.Amulet            = ChkAmulet.IsChecked != null && ChkAmulet.IsChecked.Value;

            // skills
            _selectedUser.LightWeaponSkill     = Int32Helper.Parse(TxtLightWeaponSkill.Text.Trim());
            _selectedUser.HeavyWeaponSkill     = Int32Helper.Parse(TxtHeavyWeaponSkill.Text.Trim());
            _selectedUser.TwoHandedWeaponSkill = Int32Helper.Parse(TxtTwoHWeaponSkill.Text.Trim());
            _selectedUser.Blocking             = Int32Helper.Parse(TxtBlockingSkill.Text.Trim());
            _selectedUser.Slipping             = Int32Helper.Parse(TxtSlippingSkill.Text.Trim());
            _selectedUser.Stealth = Int32Helper.Parse(TxtStealthSkill.Text.Trim());

            // henchmen
            _selectedUser.Henchmen.Level1 = Int32Helper.Parse(TxtHenchmenLevel1.Text.Trim());
            _selectedUser.Henchmen.Level2 = Int32Helper.Parse(TxtHenchmenLevel2.Text.Trim());
            _selectedUser.Henchmen.Level3 = Int32Helper.Parse(TxtHenchmenLevel3.Text.Trim());
            _selectedUser.Henchmen.Level4 = Int32Helper.Parse(TxtHenchmenLevel4.Text.Trim());
            _selectedUser.Henchmen.Level5 = Int32Helper.Parse(TxtHenchmenLevel5.Text.Trim());
        }
Exemple #7
0
        private async void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            bool success = false;

            if (PBKDF2.ValidatePassword(PswdCurrentPassword.Password, Admin ? AppState.AdminPassword : AppState.CurrentUser.Password) && PswdNewPassword.Password == PswdConfirmPassword.Password && PswdCurrentPassword.Password != PswdNewPassword.Password)
            {
                if (Admin && await AppState.ChangeAdminPassword(PBKDF2.HashPassword(PswdNewPassword.Password)).ConfigureAwait(false))
                {
                    AppState.DisplayNotification("Successfully changed administrator password.", "Time Clock");
                    success = true;
                }
                else if (!Admin)
                {
                    User newUser = new User(AppState.CurrentUser)
                    {
                        Password = PBKDF2.HashPassword(PswdNewPassword.Password)
                    };
                    if (await AppState.ChangeUserDetails(AppState.CurrentUser, newUser).ConfigureAwait(false))
                    {
                        AppState.DisplayNotification("Successfully changed user password.", "Time Clock");
                        AppState.CurrentUser.Password = newUser.Password;
                        success = true;
                    }
                }
            }
            else if (PswdCurrentPassword.Password == PswdNewPassword.Password)
            {
                AppState.DisplayNotification("The new password can't be the same as the current password.", "Time Clock");
                PswdNewPassword.Focus();
            }
            else if (PswdNewPassword.Password != PswdConfirmPassword.Password)
            {
                AppState.DisplayNotification("Please ensure the new passwords match.", "Time Clock");
                PswdConfirmPassword.Focus();
            }
            else
            {
                AppState.DisplayNotification("Invalid current password.", "Time Clock");
                PswdCurrentPassword.Focus();
            }

            if (success)
            {
                AppState.GoBack();
            }
        }
 private async void BtnCreate_Click(object sender, RoutedEventArgs e)
 {
     if (PswdPassword.Password == PswdConfirm.Password)
     {
         if (TxtUsername.Text.Trim().Length >= 4 && PswdPassword.Password.Trim().Length >= 4 && PswdConfirm.Password.Trim().Length >= 4)
         {
             _createUser.Name = TxtUsername.Text.Trim();
             if (!GameState.AllUsers.Exists(user => user.Name == _createUser.Name))
             {
                 if (!GameState.ReservedNames.Any(name => name.Equals(_createUser.Name, StringComparison.OrdinalIgnoreCase)))
                 {
                     _createUser.Password = PBKDF2.HashPassword(PswdPassword.Password.Trim());
                     if (await GameState.NewUser(_createUser))
                     {
                         _blnStart = true;
                         ClosePage();
                     }
                 }
                 else
                 {
                     GameState.DisplayNotification("That username is reserved and cannot be chosen.", "Assassin");
                 }
             }
             else
             {
                 GameState.DisplayNotification("That username is taken.", "Assassin");
             }
         }
         else
         {
             GameState.DisplayNotification("Usernames and passwords must be at least 4 characters in length, excluding leading and trailing spaces.", "Assassin");
         }
     }
     else
     {
         GameState.DisplayNotification("Please ensure the typed passwords match.", "Assassin");
     }
 }
Exemple #9
0
        private void SetupWebUser()
        {
            string name, pwd = "", confirmPwd = "";

            Console.WriteLine("A new web user has to be created.");
            Console.Write("Enter Username: "******"Enter Password: "******"Confirm Password: "******"Passwords don't match.");
                }
            } while (!pwd.Equals(confirmPwd));

            Database.InsertWebUser(new WebUser(name, PBKDF2.HashPassword(Util.Md5(pwd))));
        }
Exemple #10
0
        /// <summary>Adds a new <see cref="User"/> to the database.</summary>
        private async Task NewUser()
        {
            User checkUser = await AppState.LoadUser(TxtUsername.Text).ConfigureAwait(false);

            if (checkUser == new User() || checkUser == null)
            {
                if (PswdPassword.Password.Length >= 4 && PswdPassword.Password == PswdConfirm.Password)
                {
                    Dispatcher.Invoke(() =>
                    {
                        AppState.CurrentUser.Username  = TxtUsername.Text.Trim();
                        AppState.CurrentUser.FirstName = TxtFirstName.Text.Trim();
                        AppState.CurrentUser.LastName  = TxtLastName.Text.Trim();
                        AppState.CurrentUser.Password  = PBKDF2.HashPassword(PswdPassword.Password.Trim());
                    });
                    if (AppState.CurrentUser.Roles.ToList().Count > 0)
                    {
                        if (await AppState.NewUser(AppState.CurrentUser).ConfigureAwait(false))
                        {
                            Dispatcher.Invoke(() => AppState.GoBack());
                        }
                    }
                    else
                    {
                        AppState.DisplayNotification("There are no roles assigned to this User.", "Time Clock");
                    }
                }
                else
                {
                    AppState.DisplayNotification("Please ensure the passwords match and are at least 4 characters in length.", "Time Clock");
                }
            }
            else
            {
                AppState.DisplayNotification("This username has already been taken.", "Time Clock");
            }
        }
Exemple #11
0
 private async void BtnCreate_Click(object sender, RoutedEventArgs e)
 {
     if (TxtUsername.Text.Length > 0)
     {
         if (PswdPassword.Password.Length >= 4 && PswdConfirmPassword.Password.Length >= 4)
         {
             if (PswdPassword.Password == PswdConfirmPassword.Password)
             {
                 User newUser = new User(TxtUsername.Text, PBKDF2.HashPassword(PswdPassword.Password));
                 if (!await AppState.CreateUser(newUser))
                 {
                     TxtUsername.Focus();
                 }
                 else
                 {
                     AppState.GoBack();
                 }
             }
             else
             {
                 AppState.DisplayNotification("Please ensure that your passwords match.", "Personal Tracker");
                 PswdPassword.Focus();
             }
         }
         else
         {
             AppState.DisplayNotification("Please ensure that your passwords are at least 4 characters in length.", "Personal Tracker");
             PswdPassword.Focus();
         }
     }
     else
     {
         AppState.DisplayNotification("Please ensure that your username is filled out.", "Personal Tracker");
         TxtUsername.Focus();
     }
 }
Exemple #12
0
        private void _on_BtnCreate_pressed()
        {
            Hero createHero = new Hero();

            try
            {
                createHero = GameState.AllHeroes.Find(hero => hero.Name == TxtHeroName.Text);
            }
            catch (ArgumentNullException)
            {
            }
            if (!string.IsNullOrWhiteSpace(createHero?.Name))
            {
                LblError.Text = "This username has already been taken. Please choose another.";
                TxtHeroName.GrabFocus();
            }
            else
            {
                if (TxtHeroName.Text.Length >= 4 && PswdPassword.Text.Length >= 4)
                {
                    if (PswdPassword.Text.Trim() == PswdConfirm.Text.Trim())
                    {
                        Hero newHero = new Hero(
                            TxtHeroName.Text.Trim(),
                            PBKDF2.HashPassword(PswdPassword.Text.Trim()),
                            _selectedClass,
                            1,
                            0,
                            0,
                            250,
                            new Attributes(
                                _selectedClass.Strength,
                                _selectedClass.Vitality,
                                _selectedClass.Dexterity,
                                _selectedClass.Wisdom),
                            new Statistics(
                                _selectedClass.CurrentHealth,
                                _selectedClass.MaximumHealth,
                                _selectedClass.CurrentMagic,
                                _selectedClass.MaximumMagic),
                            new Equipment(
                                new Item(),
                                new Item(),
                                new Item(),
                                new Item(),
                                new Item(),
                                new Item(),
                                new Item(),
                                new Item()),
                            new Spellbook(),
                            new List <Item>(),
                            new Bank(0, 0, 250),
                            new Progression(),
                            ChkHardcore.Pressed,
                            new List <Quest>());

                        GameState.NewHero(newHero);
                        GameState.CurrentHero = GameState.AllHeroes.Find(hero => hero.Name == newHero.Name);
                        GetTree().ChangeScene("scenes/city/CityScene.tscn");
                    }
                    else
                    {
                        LblError.Text = "Please ensure that the passwords match.";
                    }
                }
                else
                {
                    LblError.Text = "Names and passwords have to be at least 4 characters.";
                }
            }
        }