3

Captcha コントロールのよりアクセスしやすい代替手段として、「反ロボット」の質問を CreateUserWizard に追加したいと考えています。私はaspにかなり慣れていないので、WinFormsの考え方に少し固執していることに気づきました。しかし、私はうまくいくように見えるものを思いつきました。

マークアップ:

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
    .
    .
    <tr>
      <td align="right">
        <asp:Label ID="AntiRobotQuestion" runat="server" AssociatedControlID="AntiRobotAnswer">
          Question:
        </asp:Label>
      </td>
      <td>
        <asp:TextBox ID="AntiRobotAnswer" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="AntiRobotAnswerRequired" runat="server" ControlToValidate="AntiRobotAnswer" ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="CreateUserWizard1">
        </asp:RequiredFieldValidator>
      </td>
    </tr>
    <tr>
      <td align="center" colspan="2" style="color:Red;">
        <asp:Literal ID="CustomErrorMessage" runat="server" Visible="False" EnableViewState="False"></asp:Literal>
      </td>
    </tr>
  .
  .
  </asp:CreateUserWizard>

コードビハインド:

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack) {
        //Set up the Anti-Robot Question and Answer
        Label robotQuestion = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AntiRobotQuestion");
        //Simulate randomly selecting a question and answer from a database table...
        robotQuestion.Text = "What is the capital of France";
        Session["AntiRobotAnswer"] = "Paris";
    }

}

protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
    //Check the anti-robot Q & A
    TextBox robotAnswer = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AntiRobotAnswer");
    if (robotAnswer.Text != (string)Session["AntiRobotAnswer"])
    {
        Literal errorMessage = (Literal)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("CustomErrorMessage");
        errorMessage.Text = "Wrong answer! Are you a robot?";
        errorMessage.Visible = true;
        e.Cancel = true;
    }

}

これは、これをコーディングする受け入れ可能な方法ですか? 特に 2 つの点は、私には少し「乱雑」に見えます。

  1. マークアップ内のコントロールへの参照を引き出すための FindControl の使用。
  2. 予想される回答をセッション変数に格納します。(どのくらい安全ですか?)

編集 (2012-01-23) いくつかの有効な設計の代替案が示されています。ただし、この質問と回答の手法を使用する正当な理由があります (おそらくハニーポットのアイデアに加えて)。たとえば、フォーラムの主題に関連する質問は、人間のスパマーやボットを防ぐのに役立ちます. 問題は、上記のコードはこれを行うための受け入れ可能な方法ですか? WinForms のバックグラウンドから来て、私には少しぎこちないように見えますが、それが asp の本来の姿なのかもしれません。

4

1 に答える 1

2

私が言ったように、私はあなたがパリを求めるという考えが好きではありません.

  1. 最も簡単な方法は、目に見えないフィールドを使用して、ボットがデータで埋めたかどうかを確認することです。ハニーポットのアイデアhttp://haacked.com/archive/2007/09/11/honeypot-captcha.aspx

  2. また、asp.net ツールキットの NoBot を使用することもできます http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/NoBot/NoBot.aspx

  3. この SO 記事には他にも多くのアイデアがあります。Practical non-image based CAPTCHA approach?

于 2012-01-20T00:25:29.437 に答える