MyCaptcha in CreateUserWizard

Nov 11, 2009 at 2:15 PM

Hello,

Is possible to use MyCaptcha in my CreateUserWizard control for Membership ?

Is it possible to validate with CustomValidator ?

 

Regards

 

Marco

Coordinator
Nov 11, 2009 at 5:21 PM
Edited Nov 13, 2009 at 5:28 AM

Of course it is. To use MyCaptcha with CreateUserWizard, you must first provide anonymouse access to GetImgText.ashx file so that users can see the Captcha image before they are logged in.

You can do so by adding a location section to your project's web.config file:

  <location path="GetImgText.ashx"> 
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
Next, add a CreateUserWizard control to your desired page, open its smart tag and select Customize Create User Step. This way 
you will have access to the control's content. Now add a row to the table containing control's elements and insert an instance 
of MyCaptcha user control there. Don't forget to give the control a nice name like CreateUserCaptcha!
Now in order to check whether the captcha text is correct or not, assign an event handler to CreatingUser event of CreateUserWizard control
and check the IsValid property value. You can assign the value of
IsValid property to e.Cancel within the event handler.
The point is that CreateUserWizard control does not let you access the internal controls
directly so you must find the related instance of MyCaptcha control
and call its IsValid property.
To do so, you have to write a recursive function to inspect the child controls exhaustively and find a control based on it's ID (Name).
I wrote a simple one for you :
public static class ControlHelper
{
	public static void FindByID(this Control instance,string controlName, ref Control returnedObject)
    {
        foreach (Control child in instance.Controls)
        {
            if (child.ID != null && child.ID.Equals(controlName))
            {
                returnedObject = child;
                break;
            }
            else
                child.FindByID(controlName, ref returnedObject);
        }
    }
}
As you see FindByID is an extension method to type Control so you can use it with any control.
now use this extension method to find the inner MyCaptcha control and examine its IsValid property:
	Control c = null;
        CreateUserWizard1.FindByID("CreateUserCaptcha", ref c);
        if (c != null)
        {
            MyCaptcha myCaptcha = c as MyCaptcha;
            e.Cancel = !myCaptcha.IsValid;
        }
I uploaded  sample project here. Download and see to it. Unfortunately there is noway to use a Validator control with MyCaptcha 
for now.
 
Nov 12, 2009 at 7:51 AM

Thank You for help,

 

I tried to see your sample project at http://www.filedony.com/fileupload/download.php?file=c70865a10b5fca1878f9144c75aaaa13

 

but the url seem not correct, the page give me this msg.

Invalid download link.

 

Can send me the right link ?

 

Thank You

Marco


 

 

 

Coordinator
Nov 13, 2009 at 5:14 AM
Edited Nov 13, 2009 at 5:22 AM
Hi Marco
Here is the sample website's new link.

 

On Fri, Nov 13, 2009 at 9:38 AM, mtugnoli <notifications@codeplex.com> wrote:

From: mtugnoli

Thank You for help,

 

I tried to see your sample project at http://www.filedony.com/fileupload/download.php?file=c70865a10b5fca1878f9144c75aaaa13

 

but the url seem not correct, the page give me this msg.

Invalid download link.

 

Can send me the right link ?

 

Thank You

Marco


 

 

 

Oct 3, 2011 at 10:50 AM

iam using this captha in sharepoint 2010 iam unable to get ashx  file....... its is giving like acces denied......what changes  should i make in  web.config file,i have given anonymous acces to mycaptcha  user control