Dipa Ahuja

Dipa Ahuja

  • NA
  • 3.3k
  • 711.5k

problem with CaptchaControl

Feb 7 2010 12:39 PM
hi.. m using CaptchaControl in createuserwizard control.. bt it just passed ok even though i entered wrong text

here is my code:

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="cc2" %>
    <%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc2" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
       <table id="Table2" width="100%" cellpadding="0" cellspacing="0">
<tr>     
<td valign="bottom" align="center" >
<FONT size="+2"><b>New User</b></FONT></td> </tr>
</table>
    <br /><br />
        
      
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
  Font-Names="Verdana" 
  BackColor="#E3EAEB"
  Font-Size="0.8em"  
  BorderWidth="1px" 
  BorderColor="#E6E2D8" 
  BorderStyle="Solid"  
  CompleteSuccessText="The account has been successfully created." 
  UnknownErrorMessage="The account was not created. Please try again."
  OnCreatedUser="CreateUserWizard1_CreatedUser" Width="450px" OnFinishButtonClick="CreateUserWizard1_FinishButtonClick"> 

<WizardSteps>

<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Step 1: Basic User Information">
    <ContentTemplate>

<table style="font-size: 10pt; font-family: Verdana" border="0" width="450">
<tr>
    <td style="font-weight: bold; color: white; background-color: #6b696b" align="center" colspan="2">
        Create Your UserID
    </td>
</tr>
<tr>
<%-- user id --%>
<td align="right" style="width: 153px">
  <asp:Label ID="UserNameLabel" runat="server" Text="User ID" AssociatedControlID="UserName"/>
</td>
<td>
    <asp:TextBox ID="UserName" runat="server"/>
    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
    ToolTip="User Name is required."
    ErrorMessage="User Name is required." Text="*" 
    ValidationGroup="CreateUserWizard1" ControlToValidate="UserName"/>    
</td>
</tr>

<tr>
<%-- password --%>

    <td align="right" style="width: 153px">
    <asp:Label ID="PasswordLabel" runat="server" Text="Password:" AssociatedControlID="Password"/>
    </td>
    <td>
    <asp:TextBox ID="Password" runat="server" TextMode="Password" TargetControlID="Password" />
    <cc1:PasswordStrength ID="PasswordStrength1" 
    runat="server" TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent"
    PreferredPasswordLength="6" 
    StrengthIndicatorType="Text" 
    TargetControlID="Password"/> 
    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
    ToolTip="Password is required."
      Text="*" ErrorMessage="Password is required." 
      ValidationGroup="CreateUserWizard1" 
      ControlToValidate="Password"/>      
</td>
</tr>

<tr>
<td align="right" style="width: 1
    
    53px">
    <asp:Label ID="ConfirmPasswordLabel"
     Text="Re-Type Password:" runat="server" AssociatedControlID="ConfirmPassword"/>
</td>
<td>
    <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"/>
    <asp:CompareValidator ID="CompareValidator1" runat="server"
     ErrorMessage="Password not matched" Text="*" ControlToCompare="ConfirmPassword" 
     ControlToValidate="Password"  ValidationGroup="CreateUserWizard1"/>
</td>
</tr>
<tr>
<%-- email --%>

    <td align="right" style="width: 153px; height: 15px">
     <asp:Label Text="Email:" ID="EmailLabel" runat="server" AssociatedControlID="Email"/>
    </td>
    <td style="height: 15px">
        <asp:TextBox ID="Email" runat="server"/>
        
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
            runat="server" ControlToValidate="email"
            ErrorMessage="Email Addr Invalid" Font-Size="Smaller" Text="Invalid format"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"/>
            
        <asp:RequiredFieldValidator ID="EmailRequired" 
        runat="server" ToolTip="Email is required." Text="*"
        ErrorMessage="Email is required" ValidationGroup="CreateUserWizard1" 
        ControlToValidate="Email"/>
     </td>
</tr>
</table>

</ContentTemplate>
    </asp:CreateUserWizardStep>


<asp:WizardStep ID="WizardStep1" runat="server" Title="next3">
Identify the Word:<br />
    <cc2:CaptchaControl ID="CaptchaControl1" runat="server" 
    BackColor="White" CaptchaChars="ACDEFGHJKLNPQRTUVXYZ2346789"
        CaptchaMinTimeout="3" FontColor="Black" LineColor="Black" 
        NoiseColor="Black" /><br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    &nbsp;<br />
</asp:WizardStep>

<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

</asp:CompleteWizardStep>

</WizardSteps>

<TitleTextStyle Font-Bold="True" BackColor="#1C5E55" ForeColor="White"/>
    <SideBarStyle BackColor="#1C5E55" Font-Size="0.9em" VerticalAlign="Top" />
    <SideBarButtonStyle ForeColor="White" />
    <ContinueButtonStyle BackColor="White" BorderColor="#C5BBAF" BorderStyle="Solid"
        BorderWidth="1px" Font-Names="Verdana" ForeColor="#1C5E55" />
    <NavigationButtonStyle BackColor="White" BorderColor="#C5BBAF" BorderStyle="Solid"
        BorderWidth="1px" Font-Names="Verdana" ForeColor="#1C5E55" />
    <HeaderStyle BackColor="#666666" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="2px"
        Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
    <CreateUserButtonStyle BackColor="White" BorderColor="#C5BBAF" BorderStyle="Solid"
        BorderWidth="1px" Font-Names="Verdana" ForeColor="#1C5E55" />
    <StepStyle BorderWidth="0px" />
    <StepNavigationTemplate>
        <asp:Button ID="StepPreviousButton" runat="server" BackColor="White" BorderColor="#507CD1"
            BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="MovePrevious"
            Font-Names="Verdana" ForeColor="#284E98" Text="Previous" />
        <asp:Button ID="StepNextButton" runat="server" BackColor="White" BorderColor="#507CD1"
            BorderStyle="Solid" BorderWidth="1px" CommandName="MoveNext" Font-Names="Verdana"
            ForeColor="#284E98" Text="Next" />
    </StepNavigationTemplate>
</asp:CreateUserWizard>


.CS

 public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

       
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

        p.Country = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Country")).SelectedValue;
        p.Gender = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Gender")).SelectedValue;
        p.FirstName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtfname")).Text;
        p.Email = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
        p.LastName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtlname")).Text;
        //p.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtaddr")).Text;
        p.BirthDate = Convert.ToDateTime(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtbdate")).Text);
        // p.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("city")).Text;
        //  p.PostCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtpcode")).Text;
        //  p.State = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtstat")).Text;
        if (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPictureURL")).Text == null)
        {
            p.uimage = "";
        }
        else
        {
            p.uimage = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPictureURL")).Text;
        }
        //// Save the profile - must be done since we explicitly created this profile instance

        p.Save();

       

    }


protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        TextBox t = (TextBox)CreateUserWizard1.WizardSteps[1].FindControl("TextBox1");
        CaptchaControl1.ValidateCaptcha(t.Text);

        if (!CaptchaControl1.UserValidated)
        {
            System.Windows.Forms.MessageBox.Show("You Have Entered wrong word");
            return;
            t.Focus();
        }

    }



Answers (5)