Beispiel #1
0
        public Match(string title, int rounds, int maxPlayers, int roundLength)
        {
            MatchUid = HashManager.GenerateSecureRandomToken();

            Title       = title;
            Rounds      = rounds;
            MaxPlayers  = maxPlayers;
            RoundLength = roundLength;

            Players                 = new ObservableCollection <Player>();
            PlayedPlayers           = new List <Player>();
            PickedWords             = new ObservableCollection <Word>();
            RemainingTime           = RoundLength;
            CurrentRound            = 1;
            _currentPreparationTime = PreparationTime;

            _preparationTimer          = new Timer(1000);
            _preparationTimer.Elapsed += PreparationTimerTicked;

            _subRoundTimer          = new Timer(1000);
            _subRoundTimer.Elapsed += SubRoundTimerTicked;

            PreparationTimeFinished += Match_PreparationTimeFinished;
            SubRoundFinished        += Match_SubRoundFinished;
        }
Beispiel #2
0
        public static int CreateUser(string username, string password, int minUsernameLength, int maxUsernameLength)
        {
            if (GetUser(username) != null)
            {
                throw new UserAlreadyExitsException();
            }

            if (username.Length < minUsernameLength)
            {
                throw new UsernameTooShortException();
            }

            if (username.Length > maxUsernameLength)
            {
                throw new UsernameTooLongException();
            }

            string salt         = HashManager.GenerateSecureRandomToken();
            string passwordHash = HashManager.HashSha256(password + salt);

            string query = "INSERT INTO users (username, password) VALUES " +
                           "(@username, @password)";

            DbManager.PrepareQuery(query);
            DbManager.BindValue("@username", username.ToLower());
            DbManager.BindValue("@password", passwordHash);
            DbManager.ExecutePreparedInsertUpdateDelete();

            int userId = DbManager.GetLastId();

            query = "INSERT INTO user_salt (userID, salt) VALUES " +
                    $"({userId}, '{salt}')";
            DbManager.InsertUpdateDelete(query);

            return(userId);
        }
Beispiel #3
0
 public App()
 {
     Uid = HashManager.GenerateSecureRandomToken(64);
 }