示例#1
0
        [ResponseCache(Duration = 60 * 60)]       // Cache for one hour.
#endif
        public async Task <IActionResult> Combinations([FromQuery] PhraseStrength?s)
        {
            IncrementUsage(1);

            // Return information about the number of combinations as a JSON object.
            var result = new JsonRangedCombinationContainer();

            using (var random = await _Terninger.CreateCypherBasedGeneratorAsync())
            {
                var dictionary   = _DictionaryService.ReadReadablePassphraseDictionary();
                var generator    = this.GetGenerator(dictionary, random);
                var strength     = s.HasValue ? s.Value : DefaultPhraseStrength;
                var combinations = generator.CalculateCombinations(strength);

                // This is reported as a range instead of just the usual single value.
                result.middle = new JsonCombinationContainer()
                {
                    combinations = combinations.OptionalAverage
                };
                result.middle.rating = _RatingService.Rate(result.middle.combinations);
                result.upper         = new JsonCombinationContainer()
                {
                    combinations = combinations.Longest
                };
                result.upper.rating = _RatingService.Rate(result.upper.combinations);
                result.lower        = new JsonCombinationContainer()
                {
                    combinations = combinations.Shortest
                };
                result.lower.rating = _RatingService.Rate(result.lower.combinations);
            }
            return(Json(result));
        }
示例#2
0
        [OutputCache(Duration = 60 * 60)]       // Cache for one hour.
#endif
        public async Task <ActionResult> Combinations(PhraseStrength?s)
        {
            // Return information about the number of combinations as a JSON object.
            var result = new JsonRangedCombinationContainer();

            using (var random = await RandomService.PooledGenerator.CreateCypherBasedGeneratorAsync())
            {
                var generator    = this.GetGenerator(random);
                var strength     = s.HasValue ? s.Value : DefaultPhraseStrength;
                var combinations = generator.CalculateCombinations(strength);

                // This is reported as a range instead of just the usual single value.
                result.middle = new JsonCombinationContainer()
                {
                    combinations = combinations.OptionalAverage
                };
                result.upper = new JsonCombinationContainer()
                {
                    combinations = combinations.Longest
                };
                result.lower = new JsonCombinationContainer()
                {
                    combinations = combinations.Shortest
                };
            }
            return(new JsonNetResult(result));
        }