{"id":19560048,"url":"https://github.com/plotdb/captcha","last_synced_at":"2025-07-17T04:34:48.442Z","repository":{"id":57137261,"uuid":"324576161","full_name":"plotdb/captcha","owner":"plotdb","description":"captcha abstract layer and wrappers for available services","archived":false,"fork":false,"pushed_at":"2022-01-07T06:15:18.000Z","size":675,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T22:40:07.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plotdb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-26T14:53:03.000Z","updated_at":"2022-01-07T06:15:22.000Z","dependencies_parsed_at":"2022-09-01T03:00:51.913Z","dependency_job_id":null,"html_url":"https://github.com/plotdb/captcha","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fcaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fcaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fcaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fcaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotdb","download_url":"https://codeload.github.com/plotdb/captcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240817083,"owners_count":19862418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:05:43.359Z","updated_at":"2025-02-26T08:27:41.251Z","avatar_url":"https://github.com/plotdb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# captcha\n\nCaptcha wrapper for captcha services.\n\n\n## Usage\n\ninclude `captcha.js`:\n\n    \u003cscript src=\"dist/captcha.js\"\u003e\u003c/script\u003e\n\n\nuse `captcha` object to create captcha service wrappers like this:\n\n    mycaptcha = new captcha({\n      init: function() { Promise.resolve('...'); },\n      get: function(opt) { Promise.resolve('...'); }\n      isVerifyFailed: function(err) { ... }\n      alt: { ... },\n      config: { ... }\n      lc: { ... }\n    });\n\nwith following options:\n\n - `init()`: function for initializing your captcha.\n   - will be called only once and always called automatically when get is called.\n   - should return Promise.\n - `get(opt)`: function used to getting captcha token for verifying through backend.\n   - should return Promise resolving object with `token` field ( `{token: ... }` ).\n   - `opt` is defined by user.\n\n   - if captcha verification failed, reject with an error which can be recognize with `isVerifyFailed`.\n\n - isVerifyFailed(err): optional function to check if a given error object `err` is for verification failure.\n   - if `alt` is provided and when `execute` calls callback function but an error for verification failure is returned by the callback function, then `captcha` will try again with another captcha object corresponding to `alt`.\n   - check below section for how `execute` works.\n - `alt`: optional. either an object for captcha constructor options, or a captcha object.\n    - if set, `alt` will be used when veritification failed with the owner `captcha` object.\n - `config`: default config object for this `captcha` object.\n    - this is designed for providing configuration to user defined `get` and `init` functions.\n - `lc`: object storing default value for storing variables defined by `get` and `init` functions.\n \nOnce constructed, you can get a token by:\n\n    mycaptcha.get().then(function(opt) { opt.token; });\n\nSince `token` usually involves server-side verification, you can use `execute` for alt captcha\n\n    postData = function({ .../* object returned by `get` */... }) {\n      /* should return promise */\n      Promise.resolve!\n        .then -\u003e /* fetch, ajax with the `get` returned object */\n    };\n\n    mycaptcha.execute({ ... /* options to `get` */ ... }, postData).then(function() { ... });\n\n\n## API\n\n - `get(opt)`: get captcha token. should return Promise resolving `{token}` object.\n   - `opt`: user defined option for using in user defined `get` function.\n - `execute(opt, cb)`: execute cb with get returned object. return promise\n   - `opt`: options passed to `get`.\n   - `cb(ret)`: callback functions with `get` returned object as option ( `ret` ).\n     - `cb` should return Promise.\n       If verification failed, `cb` can optionally rejects with error object recognizable by `isVerifyFailed`. \n - `setConfig`: update `config` object.\n\n## ReCaptcha\n\n`captcha` ships with predefined Google Recaptcha wrapper. use it by first including the needed js:\n\n    \u003cscript src=\"dist/captcha.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"dist/recaptcha.js\"\u003e\u003c/script\u003e\n\n\nthen:\n\n    recaptcha.v2.setConfig({sitekey: '....', enabled: ture});\n    recaptcha.v2.get();\n\n    recaptcha.v3.setConfig({sitekey: '....', enabled: ture});\n    recaptcha.v3.get();\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fcaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotdb%2Fcaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fcaptcha/lists"}