コード例 #1
0
ファイル: AccountService.cs プロジェクト: anaspoiala/bonsai
        private void ValidatePassword(string password)
        {
            if (TextValidator.IsNullEmptyOrWhiteSpace(password))
            { // Password empty or not provided.
                throw new ValidationException("Password can't be empty!");
            }

            if (!TextValidator.ContainsLowerLetters(password) || !TextValidator.ContainsUpperLetters(password))
            { // Password doesn't contain both uppercase and lowercase letters.
                throw new ValidationException("Password must contain both uppercase and lowecase letters!");
            }

            if (!TextValidator.ContainsNumbers(password) && !TextValidator.ContainsSymbols(password))
            { // Pasword doesn't contain neither numbers nor symbols.
                throw new ValidationException("Password must contain at least one number or symbol!");
            }

            if (!TextValidator.ContainsBetweenXAndYCharacters(password, 8, 32))
            { // Password doesn't have between 8 and 32 characters length.
                throw new ValidationException("Password must contain between 8 and 32 characters!");
            }
        }
コード例 #2
0
ファイル: AccountService.cs プロジェクト: anaspoiala/bonsai
        private void ValidateUsername(string username)
        {
            if (repository.GetAccountByUsername(username) != null)
            { // Username already exists in the database.
                throw new ValidationException("Username already exists!");
            }

            if (TextValidator.IsNullEmptyOrWhiteSpace(username))
            { // Username empty or not provided.
                throw new ValidationException("Username can't be empty!");
            }

            if (!TextValidator.ContainsBetweenXAndYCharacters(username, 8, 32))
            { // Username doesn't contain between 8 and 32 characters.
                throw new ValidationException("Username must contain between 8 and 32 characters!");
            }

            if (!TextValidator.ContainsLetters(username))
            {  // Username doesn't contain any letters (only numbers or symbols).
                throw new ValidationException("Username must contain at least one letter!");
            }
        }