You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/09-Plugins/19-login-captcha.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,39 @@ plugins: [
46
46
]
47
47
```
48
48
49
+
## Preventing token reuse
50
+
51
+
A captcha token stays valid at the provider for a short period, which means the same token could be replayed for several logins. To prevent this, pass an optional [key-value adapter](/docs/tutorial/Adapters/key-value-adapters) via `keyValueAdapter`. Each token is recorded once it has been used for a successful login, and any later attempt with the same token is rejected.
52
+
53
+
```bash
54
+
pnpm i @adminforth/key-value-adapter-ram
55
+
```
56
+
57
+
```ts title="./resources/adminuser.ts"
58
+
// Import the plugin, captcha adapter and a key-value adapter
siteKey: "YOUR_SITE_KEY", // Replace with your site key
69
+
secretKey: "YOUR_SECRET_KEY", // Replace with your secret key
70
+
}),
71
+
// Store used tokens to prevent them from being replayed
72
+
keyValueAdapter: newRamKeyValueAdapter(),
73
+
// Optional: how long (in seconds) a used token is remembered. Should be at least as long
74
+
// as the captcha provider keeps the token valid. Defaults to 300 (5 minutes).
75
+
tokenTimeToLiveSeconds: 300,
76
+
}),
77
+
]
78
+
```
79
+
80
+
You can use any of the available [key-value adapters](/docs/tutorial/Adapters/key-value-adapters) (RAM, Redis, LevelDB or Resource-based). For multi-process or replicated deployments use a centralized adapter such as Redis, so used tokens are shared across all processes.
81
+
49
82
## Result
50
83
51
84
After setting up the plugin, your login page will include a captcha. Below is an example of how it will look:
0 commit comments