当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

no-captcha

No CAPTCHA reCAPTCHA For Laravel.
授权协议 MIT License
开发语言 PHP
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 上官高翰
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

No CAPTCHA reCAPTCHA

recaptcha_anchor 2x

For Laravel 4 use v1 branch.

Installation

composer require anhskohbo/no-captcha

Laravel 5 and above

Setup

NOTE This package supports the auto-discovery feature of Laravel 5.5 and above, So skip these Setup instructions if you're using Laravel 5.5 and above.

In app/config/app.php add the following :

1- The ServiceProvider to the providers array :

Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,

2- The class alias to the aliases array :

'NoCaptcha' => Anhskohbo\NoCaptcha\Facades\NoCaptcha::class,

3- Publish the config file

php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"

Configuration

Add NOCAPTCHA_SECRET and NOCAPTCHA_SITEKEY in .env file :

NOCAPTCHA_SECRET=secret-key
NOCAPTCHA_SITEKEY=site-key

(You can obtain them from here)

Usage

Init js source

With default options :

{!! NoCaptcha::renderJs() !!}

With language support or onloadCallback option :

{!! NoCaptcha::renderJs('fr', true, 'recaptchaCallback') !!}

Display reCAPTCHA

Default widget :

{!! NoCaptcha::display() !!}

With custom attributes (theme, size, callback ...) :

{!! NoCaptcha::display(['data-theme' => 'dark']) !!}

Invisible reCAPTCHA using a submit button:

{!! NoCaptcha::displaySubmit('my-form-id', 'submit now!', ['data-theme' => 'dark']) !!}

Notice that the id of the form is required in this method to let the autogeneratedcallback submit the form on a successful captcha verification.

Validation

Add 'g-recaptcha-response' => 'required|captcha' to rules array :

$validate = Validator::make(Input::all(), [
	'g-recaptcha-response' => 'required|captcha'
]);
Custom Validation Message

Add the following values to the custom array in the validation language file :

'custom' => [
    'g-recaptcha-response' => [
        'required' => 'Please verify that you are not a robot.',
        'captcha' => 'Captcha error! try again later or contact site admin.',
    ],
],

Then check for captcha errors in the Form :

@if ($errors->has('g-recaptcha-response'))
    <span class="help-block">
        <strong>{{ $errors->first('g-recaptcha-response') }}</strong>
    </span>
@endif

Testing

When using the Laravel Testing functionality, you will need to mock out the response for the captcha form element.

So for any form tests involving the captcha, you can do this by mocking the facade behavior:

// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
    ->once()
    ->andReturn(true);

// provide hidden input for your 'required' validation
NoCaptcha::shouldReceive('display')
    ->zeroOrMoreTimes()
    ->andReturn('<input type="hidden" name="g-recaptcha-response" value="1" />');

You can then test the remainder of your form as normal.

When using HTTP tests you can add the g-recaptcha-response to the request body for the 'required' validation:

// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
    ->once()
    ->andReturn(true);

// POST request, with request body including g-recaptcha-response
$response = $this->json('POST', '/register', [
    'g-recaptcha-response' => '1',
    'name' => 'John',
    'email' => 'john@example.com',
    'password' => '123456',
    'password_confirmation' => '123456',
]);

Without Laravel

Checkout example below:

<?php

require_once "vendor/autoload.php";

$secret  = 'CAPTCHA-SECRET';
$sitekey = 'CAPTCHA-SITEKEY';
$captcha = new \Anhskohbo\NoCaptcha\NoCaptcha($secret, $sitekey);

if (! empty($_POST)) {
    var_dump($captcha->verifyResponse($_POST['g-recaptcha-response']));
    exit();
}

?>

<form action="?" method="POST">
    <?php echo $captcha->display(); ?>
    <button type="submit">Submit</button>
</form>

<?php echo $captcha->renderJs(); ?>

Contribute

https://github.com/anhskohbo/no-captcha/pulls

  • easy-captcha 实现前后端分离验证码验证 maveny引入 <dependency> <groupId>com.github.whvcse</groupId> <artifactId>easy-captcha</artifactId> <version>1.6.2</version> </depe

  • 1. 添加easy-captcha依赖 <!-- 验证码 --> <dependency> <groupId>com.github.whvcse</groupId> <artifactId>easy-captcha</artifactId> <version>1.6.2</version> </dependency> 2.后端实现 @Controller

  • 解决方案: pip install django-simple-captcha

  • 在Django开发中遇到如下问题 from captcha.fields import CaptchaField ModuleNotFoundError: No module named 'captcha.fields' 解决方法: 安装django-simple-captcha pip install django-simple-captcha 在开发中遇到以下错误 HINT: Ad

  • kaptcha.border  是否有边框  默认为true  我们可以自己设置yes,no kaptcha.border.color   边框颜色   默认为Color.BLACK kaptcha.border.thickness  边框粗细度  默认为1 kaptcha.producer.impl   验证码生成器  默认为DefaultKaptcha kaptcha.textproducer

  • 使用Mac终端命令 tp5.0 安装topthink/think-captcha composer require topthink/think-captcha:* 得出 zsh: no matches found: topthink/think-captcha:* 解决方式:打开终端 vim ~/.zshrc 在最后加上 setopt no_nomatch 保存生效 source ~/.zsh

 相关资料
  • 除非通过无界通配符对其进行参数化,否则不允许转换为参数化类型。 Box<Integer> integerBox = new Box<Integer>(); Box<Number> numberBox = new Box<Number>(); //Compiler Error: Cannot cast from Box<Number> to Box<Integer> integerBox = (Bo

  • no

    描述 (Description) 如果MODULE支持,则此函数调用MODULE中定义的unimport函数来取消当前包中的所有符号,或者只调用LIST引用的符号。 可以说没有与进口相反。 语法 (Syntax) 以下是此函数的简单语法 - no Module VERSION LIST no Module VERSION no MODULE LIST no MODULE 返回值 (Return

  • 我不能运行一个简单的程序来开始理解Deeplearning4j。 我尝试了这个链接中的代码:使用Deeplearning4J在Java中进行深度学习 不幸的是,这对我不起作用。事实上,我有一个错误: SLF4J:无法加载类"org.slf4j.impl.Static LoggerBinder".SLF4J:默认为无操作(NOP)记录器实现SLF4J:有关更多详细信息,请参阅http://www.s

  • Description This jQuery plugin turns an obfuscated e-mail address into a human-readable one. It's lightweight and accepts multiple filtering levels for additional security. No Spam works on mailto lin

  • No Bullsh**是一个用PHP开发的Web动态相册系统。它能够自动扫描给定的目录,然后创建每一张图片的缩略图并展示。照片可以通过简单地点击缩略图来进行浏览或用向前/向后按纽浏览,此外还支持采用lightbox来展示原始图。 在线演示:http://www.jkemppainen.com/nbs/DEMO_1_5/

  • 基于Java语言开发的一套轻量级框架,亲手实现JSON/XML解析、服务容器、服务框架、字节码工具等解决方案,学习成本低,即插即用,扩展性高,更加轻量级! No Framework   一、序言 NoFramework是笔者在闲暇之余写的一个网络爬虫项目Seeker一路延续发展到后来的No系列的框架的诞生。一路走来,不知不觉已经快一年了,这期间有些项目有的被重写过,有的架构也发生了大的改变,还有的