https://github.com/maliming/recaptcha
reCAPTCHA for Asp Net Core 3.x & 5.x & 6.x & 7.x & 8.x & 9.x
https://github.com/maliming/recaptcha
Last synced: about 1 year ago
JSON representation
reCAPTCHA for Asp Net Core 3.x & 5.x & 6.x & 7.x & 8.x & 9.x
- Host: GitHub
- URL: https://github.com/maliming/recaptcha
- Owner: maliming
- License: mit
- Created: 2019-11-26T13:16:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T09:17:42.000Z (over 1 year ago)
- Last Synced: 2025-04-12T17:46:51.348Z (about 1 year ago)
- Language: C#
- Homepage: https://developers.google.com/recaptcha/intro
- Size: 3.13 MB
- Stars: 64
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Owl.reCAPTCHA
Google reCAPTCHA for ASP NET Core (v3 and v2)
# Demo
V3:

V3 Programmatically:

V2 Invisible:

V2 Checkbox:

# Install-Package
```
Install-Package Owl.reCAPTCHA
```
# reCAPTCHA v3
### v3 startup
```
services.AddreCAPTCHAV3(x =>
{
x.SiteKey = "your_site_key";
x.SiteSecret = "your_site_secret";
});
```
### v3 razor page
```
@addTagHelper *, Owl.reCAPTCHA
@*
Hide-the-recaptcha-badge
https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed
*@
function callback(token) {
document.getElementById("token").value = token;
}
```
```
@addTagHelper *, Owl.reCAPTCHA
document.getElementById("submitBtn").onclick = function(e) {
e.preventDefault();
grecaptcha.reExecute(function(token) {
document.getElementById("token").value = token;
document.getElementById("recaptchaForm").submit();
})
};
@*
Hide-the-recaptcha-badge
https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed
*@
```
### v3 razor page model
```
public class V3Model : PageModel
{
private readonly IreCAPTCHASiteVerifyV3 _siteVerify;
public V3Model(IreCAPTCHASiteVerifyV3 siteVerify)
{
_siteVerify = siteVerify;
}
public async Task OnPostAsync(string token)
{
var response = await _siteVerify.Verify(new reCAPTCHASiteVerifyRequest
{
Response = token,
RemoteIp = HttpContext.Connection.RemoteIpAddress.ToString()
});
/*
https://developers.google.com/recaptcha/docs/v3
response:
{
"success": true|false, // whether this request was a valid reCAPTCHA token for your site
"score": number // the score for this request (0.0 - 1.0)
"action": string // the action name for this request (important to verify)
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
}
*/
}
}
```
# reCAPTCHA v2
### v2 startup
```
services.AddreCAPTCHAV2(x =>
{
x.SiteKey = "your_site_key";
x.SiteSecret = "your_site_secret";
});
```
### v2 razor page(checkbox mode)
```
@addTagHelper *, Owl.reCAPTCHA
function callback(token) {
document.getElementById("token").value = token;
}
```
### v2 razor page(invisible mode)
```
@addTagHelper *, Owl.reCAPTCHA
function onload() {
grecaptcha.execute();
}
function callback(token) {
document.getElementById("token").value = token;
}
@*
Hide-the-recaptcha-badge
https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed
*@
```
### v2 razor page(invisible mode)
```
@addTagHelper *, Owl.reCAPTCHA
function callback(token) {
document.getElementById("token").value = token;
document.getElementById("demo-form").submit();
}
@*
Hide-the-recaptcha-badge
https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed
*@
Submit
```
### v2 razor page model
```
public class V2_CheckboxModel : PageModel
{
private readonly IreCAPTCHASiteVerifyV2 _siteVerify;
public V2_CheckboxModel(IreCAPTCHASiteVerifyV2 siteVerify)
{
_siteVerify = siteVerify;
}
public async Task OnPostAsync(string token)
{
var response = await _siteVerify.Verify(new reCAPTCHASiteVerifyRequest
{
Response = token,
RemoteIp = HttpContext.Connection.RemoteIpAddress.ToString()
});
/*
https://developers.google.com/recaptcha/docs/verify
response:
{
"success": true|false,
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
}
*/
}
}
```