// Generate a new valid option // @param numberOfOptions is optional. Defaults to 5 public void Generate(int numberOfOptions = DefaultNumberOfImages) { var visualCaptchaSession = new VisualCaptchaSession(); // Shuffle all imageOptions ImageOptions = ImageOptions.Shuffle().ToList(); if (numberOfOptions < 2) { numberOfOptions = 2; } // Get a random sample of X images // AND Set a random value for each of the images, to be used in the frontend visualCaptchaSession.Images = ImageOptions.Shuffle() .Take(numberOfOptions) .Select(x => new Option { name = x.name, path = x.path, value = Extensions.GenerateRandomKey(20) }) .ToList(); // Select a random image option, for the current valid image option (but not the last one) visualCaptchaSession.ValidImageOption = visualCaptchaSession.Images.Except(new[] { visualCaptchaSession.ValidImageOption }).Shuffle().First(); // Select a random audio option, for the current valid audio option (but not the last one) visualCaptchaSession.ValidAudioOption = AudioOptions.Except(new[] { visualCaptchaSession.ValidAudioOption }).Shuffle().First(); // Set random hashes for audio and image field names, and add it in the frontend data object visualCaptchaSession.FrontendData = new FrontendData() { values = visualCaptchaSession.Images.Select(x => x.value).ToList(), imageName = visualCaptchaSession.ValidImageOption.name, imageFieldName = Extensions.GenerateRandomKey(20), audioFieldName = Extensions.GenerateRandomKey(20), }; Session = visualCaptchaSession; }
// Generate a new valid option // @param numberOfOptions is optional. Defaults to 5 public void Generate(int numberOfOptions = DefaultNumberOfImages) { var visualCaptchaSession = new VisualCaptchaSession(); // Shuffle all imageOptions ImageOptions = ImageOptions.Shuffle().ToList(); if (numberOfOptions < 2) { numberOfOptions = 2; } // Get a random sample of X images // AND Set a random value for each of the images, to be used in the frontend visualCaptchaSession.Images = ImageOptions.Shuffle() .Take(numberOfOptions) .Select(x => new Option {name = x.name, path = x.path, value = Extensions.GenerateRandomKey(20)}) .ToList(); // Select a random image option, for the current valid image option (but not the last one) visualCaptchaSession.ValidImageOption = visualCaptchaSession.Images.Except(new[] {visualCaptchaSession.ValidImageOption}).Shuffle().First(); // Select a random audio option, for the current valid audio option (but not the last one) visualCaptchaSession.ValidAudioOption = AudioOptions.Except(new[] {visualCaptchaSession.ValidAudioOption}).Shuffle().First(); // Set random hashes for audio and image field names, and add it in the frontend data object visualCaptchaSession.FrontendData = new FrontendData() { values = visualCaptchaSession.Images.Select(x => x.value).ToList(), imageName = visualCaptchaSession.ValidImageOption.name, imageFieldName = Extensions.GenerateRandomKey(20), audioFieldName = Extensions.GenerateRandomKey(20), }; Session = visualCaptchaSession; }
public void SetSession(string key, VisualCaptchaSession value) { HttpContext.Current.Session[key] = value; }