Ejemplo n.º 1
0
        public CaptchaResult GetCaptchaImage()
        {
            //int width = 100;
            //int height = 36;
            int           width       = 140;
            int           height      = 36;
            var           captchaCode = CustomCaptcha.GenerateCaptchaCode();
            CaptchaResult result      = CustomCaptcha.GenerateCaptchaImage(width, height, captchaCode);

            //HttpContext.Session.SetString("CaptchaCode", result.CaptchaCode);
            //Stream s = new MemoryStream(result.CaptchaByteData);
            //return new FileStreamResult(s, "image/png");
            return(result);
        }
Ejemplo n.º 2
0
        private static void ExampleCustomCaptcha()
        {
            DebugHelper.VerboseMode = true;
            var randInt = new Random().Next(0, 10000);

            var api = new CustomCaptcha
            {
                ClientKey = "1234567890123456789012",
                // random here to let the same task to be assigned to the same workers
                ImageUrl   = "https://files.anti-captcha.com/26/41f/c23/7c50ff19.jpg?random=" + randInt,
                Assignment = "Enter the licence plate number",
                Forms      = new JArray
                {
                    new JObject
                    {
                        { "label", "Number" },
                        { "labelHint", false },
                        { "contentType", false },
                        { "name", "license_plate" },
                        { "inputType", "text" },
                        {
                            "inputOptions", new JObject
                            {
                                { "width", "100" },
                                { "placeHolder", "Enter letters and numbers without spaces" }
                            }
                        }
                    },
                    new JObject
                    {
                        { "label", "Car color" },
                        { "labelHint", "Select the car color" },
                        { "contentType", false },
                        { "name", "color" },
                        { "inputType", "select" },
                        {
                            "inputOptions", new JArray
                            {
                                new JObject
                                {
                                    { "value", "white" },
                                    { "caption", "White color" }
                                },
                                new JObject
                                {
                                    { "value", "black" },
                                    { "caption", "Black color" }
                                },
                                new JObject
                                {
                                    { "value", "gray" },
                                    { "caption", "Gray color" }
                                }
                            }
                        }
                    }
                }
            };

            if (!api.CreateTask())
            {
                DebugHelper.Out("API v2 send failed. " + api.ErrorMessage, DebugHelper.Type.Error);
            }
            else if (!api.WaitForResult())
            {
                DebugHelper.Out("Could not solve the captcha.", DebugHelper.Type.Error);
            }
            else
            {
                foreach (var answer in api.GetTaskSolution().Answers)
                {
                    DebugHelper.Out(
                        "The answer for the question '" + answer.Key + "' : " + answer.Value,
                        DebugHelper.Type.Success
                        );
                }
            }
        }