Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

ICaptchaFactory and ICaptcha

yueyinqiu edited this page Jan 24, 2021 · 9 revisions

ICaptchaFactory<TCaptchaDisplay, TAnswer> can produce and verify captcha.

For clients, the captcha factories used in this way:

  1. Invoke GenerateNewAsync(CancellationToken) to get a instance of ICaptcha<TCaptchaDisplay>, which has two properties called Id and Display.
  2. Record the Id and show the Display to the human user in a specific way.
  3. Get the answer of the human user.
  4. Invoke VerifyAndGetTicketAsync(string, TAnswer, CancellationToken), send the recorded id and the human's answer to verify it, then a string ticket will be received (or, if the user provided a wrong answer, the client may retry the process above).
  5. Use the ticket to access other actions.

So, the implementions should:

  • Generate the captcha and save its answer with its id in GenerateNewAsync(CancellationToken). To make the system flexible, the saving process is recommended to be delegated to other libraries. For example, ICaptchaAnswerSaver<TAnswer> in our NCaptcha.CaptchaFactories.Base just does it.
  • Verify the captcha and produce a ticket in VerifyAndGetTicketAsync(string, TAnswer, CancellationToken). To make the system flexible and make the tickets easier to be verified in other actions, the ticket producing and saving process should be delegated to a ITicketFactory.