Login Control + CAPTCHA
Posted by: Scott on Writing,
on 06 Jun 2006 |
View original | Bookmarked: 0 time(s)
My latest installment (Part 5) of the Examining ASP.NET 2.0's Membership, Rols, and Profile article series shows how to extend the Login control to add additional Web controls to the interface and how to customize the authentication logic accordingly. In particular, the article includes a demo (among others) that shows how to add a CAPTCHA to the Login control. For that demo I'm using Jeff Atwood's free (and open-source) ASP.NET CAPTCHA server control.
In short, to accomplish this perform the following tasks:
- Convert the Login control into a template. This can be done from the Designer by clicking on the Convert to Template option in the control's smart tag
- Augment the Login control's template markup to include Jeff's CAPTCHA control (my example also requires that the user enter their email address on file)
- Create an event handler for the Login control's Authenticate event. In there, verify the user's username and password via a call to Membership.ValidateUser(username, password). Assuming that that check passes, programmatically access the Email and CAPTCHA controls using LoginControlID.FindControl(ID) and verify the validity of those inputs. If the user has supplied valid inputs all around, set e.Authenticate to True; otherwise, if any check fails, set e.Authenticate to False.
That's all there is to it!
[Read the article...]