This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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:
- Invoke
GenerateNewAsync(CancellationToken)
to get a instance ofICaptcha<TCaptchaDisplay>
, which has two properties calledId
andDisplay
. - Record the
Id
and show theDisplay
to the human user in a specific way. - Get the answer of the human user.
- Invoke
VerifyAndGetTicketAsync(string, TAnswer, CancellationToken)
, send the recorded id and the human's answer to verify it, then astring
ticket will be received (or, if the user provided a wrong answer, the client may retry the process above). - 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 ourNCaptcha.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 aITicketFactory
.
In this current repository:
NCaptcha.AnswerSavers.InMemoryGuidDictionary
NCaptcha.CaptchaFactories.Base
NCaptcha.CaptchaFactories.Image
NCaptcha.TicketFactories.InMemoryGuidDictionary
In other repositories: