protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
    {
        // find captcha control
        WebControlCaptcha.CaptchaControl registerCAPTCHA = (WebControlCaptcha.CaptchaControl)PasswordRecovery1.UserNameTemplateContainer.FindControl("CAPTCHA");

        // if captcha is missing or incorrect
        if (!registerCAPTCHA.UserValidated)
        {
            // Show the error message
            FailureText.Text    = "Security Code MISSING or INCORRECT!<div class='clearBoth2'></div>";
            FailureText.Visible = true;

            // Cancel the transaction
            e.Cancel = true;
        }
    }
    // this code checks for leading and trailing spaces in username
    // and makes sure the username does not appear in the password
    protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
    {
        // find captcha control
        WebControlCaptcha.CaptchaControl registerCAPTCHA = (WebControlCaptcha.CaptchaControl)CreateUserWizardStep1.ContentTemplateContainer.FindControl("CAPTCHA");

        if (!registerCAPTCHA.UserValidated)
        {
            // Show the error message
            InvalidUserNameOrPasswordMessage.Text    = "Security Code MISSING or INCORRECT!";
            InvalidUserNameOrPasswordMessage.Visible = true;

            // Cancel the create user workflow
            e.Cancel = true;
        }

        // declare variable and assign it to the user name textbox
        string trimmedUserName = CreateUserWizard1.UserName.Trim();

        // Check for empty spaces infront and behind the string
        if (CreateUserWizard1.UserName.Length != trimmedUserName.Length)
        {
            // Show the error message
            InvalidUserNameOrPasswordMessage.Text    = "The username cannot contain leading or trailing spaces.";
            InvalidUserNameOrPasswordMessage.Visible = true;
            // Cancel the create user workflow
            e.Cancel = true;
        }
        else
        {
            // Username is valid, make sure that the password does not contain the username
            if (CreateUserWizard1.Password.IndexOf(CreateUserWizard1.UserName, StringComparison.OrdinalIgnoreCase) < 0)
            {
                return;
            }

            // Show the error message
            InvalidUserNameOrPasswordMessage.Text    = "The username may not appear anywhere in the password.";
            InvalidUserNameOrPasswordMessage.Visible = true;

            // Cancel the create user workflow
            e.Cancel = true;
        }
        SendEmail();
    }