Inheritance: System.EventArgs
Esempio n. 1
0
        // Determine the challenge and the required response
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            EnsureChildControls();

            CheckResponseAndStoreState();  // Do this (if it hasn't already been done) before preparing the next challenge

            // Default challenge is to perform a trivial complement of a number
            var eventArgs   = new NoBotEventArgs();
            var utcNow      = DateTime.UtcNow;
            var randomValue = utcNow.Millisecond;

            eventArgs.ChallengeScript  = String.Format(CultureInfo.InvariantCulture, "~{0}", randomValue.ToString(CultureInfo.InvariantCulture));
            eventArgs.RequiredResponse = (~randomValue).ToString(CultureInfo.InvariantCulture);

            // If a custom challenge has been provided, use it instead
            if (GenerateChallengeAndResponse != null)
            {
                GenerateChallengeAndResponse(this, eventArgs);
            }

            // Send down the challenge
            _extender.ChallengeScript = eventArgs.ChallengeScript;
            _extender.ClientState     = String.Empty;

            // Save values for use during postback
            ViewState[ResponseTimeKey] = utcNow.AddSeconds(_responseMinimumDelaySeconds);
            var sessionKey = CreateSessionKey(utcNow.Ticks);

            ViewState[SessionKeyKey] = sessionKey;
            Page.Session[sessionKey] = eventArgs.RequiredResponse;
        }
Esempio n. 2
0
        // Determine the challenge and the required response
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            EnsureChildControls();

            CheckResponseAndStoreState();  // Do this (if it hasn't already been done) before preparing the next challenge

            // Default challenge is to perform a trivial complement of a number
            NoBotEventArgs eventArgs = new NoBotEventArgs();
            DateTime utcNow = DateTime.UtcNow;
            int randomValue = utcNow.Millisecond;
            eventArgs.ChallengeScript = string.Format(CultureInfo.InvariantCulture, "~{0}", randomValue.ToString(CultureInfo.InvariantCulture));
            eventArgs.RequiredResponse = (~randomValue).ToString(CultureInfo.InvariantCulture);

            // If a custom challenge has been provided, use it instead
            if (null != GenerateChallengeAndResponse)
            {
                GenerateChallengeAndResponse(this, eventArgs);
            }

            // Send down the challenge
            _extender.ChallengeScript = eventArgs.ChallengeScript;
            _extender.ClientState = "";

            // Save values for use during postback
            ViewState[ResponseTimeKey] = utcNow.AddSeconds(_responseMinimumDelaySeconds);
            string sessionKey = CreateSessionKey(utcNow.Ticks);
            ViewState[SessionKeyKey] = sessionKey;
            Page.Session[sessionKey] = eventArgs.RequiredResponse;
        }
Esempio n. 3
0
    protected void NoBot1_GenerateChallengeAndResponse(object sender,
                                                       AjaxControlToolkit.NoBotEventArgs e)
    {
        NoBotState state;

        NoBot1.IsValid(out state);

        Label1.Text = state.ToString();
    }
 protected void CustomChallengeResponse(object sender, NoBotEventArgs e)
 {
     // This is a sample challenge/response implementation that involves
     // the DOM so as to make the calculation more difficult to thwart.
     // It adds a randomly sized Panel; the client must calculate the area.
     Panel p = new Panel();
     p.ID = "NoBotSamplePanel";
     Random rand = new Random();
     p.Width = rand.Next(300);
     p.Height = rand.Next(200);
     p.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
     p.Style.Add(HtmlTextWriterStyle.Position, "absolute");
     ((NoBot) sender).Controls.Add(p);
     e.ChallengeScript = string.Format("var e = document.getElementById('{0}'); e.offsetWidth * e.offsetHeight;", p.ClientID);
     e.RequiredResponse = (p.Width.Value * p.Height.Value).ToString();
 }
Esempio n. 5
0
 protected void NoBot2_GenerateChallengeAndResponse(object sender, NoBotEventArgs e)
 {
     // A simple challenge
     e.ChallengeScript = "'cHaLlEnGe'.toUpperCase()";
     e.RequiredResponse = "CHALLENGE";
 }