thytanium/captcha

此包已被放弃,不再维护。作者建议使用 mews/captcha 包。

优秀的 Laravel 验证码

v2.0 2015-03-13 21:06 UTC

This package is not auto-updated.

Last update: 2020-05-04 15:31:49 UTC


README

Captcha

安装

编辑您的 composer.json 文件

Laravel 4

"require": {
  ...
  "thytanium/captcha": "1.*"
}

Laravel 5

"require": {
  ...
  "thytanium/captcha": "2.*"
}

运行 composer update 安装包。然后在 app.php 中添加以下内容

'providers' => array(
  ...
  'Thytanium\Captcha\CaptchaServiceProvider',
);
'aliases' => array(
  'Captcha' => 'Thytanium\Captcha\Facades\Captcha',
);

然后,您必须 发布配置文件

php artisan vendor:publish --provider="Thytanium\Captcha\CaptchaServiceProvider"

使用

要使用它,只需将此 HTML 代码放在表单中的文本输入旁边即可。

<img src="{{URL::to('captcha')}}">

验证

要验证输入框中的输入文本,请将以下内容放在您的验证规则中

$rules = [
  'text_input' => 'required|captcha'
];

Validator::make($rules, Input::all());

选项

您可以通过编辑 config/captcha.php 配置文件来更改验证码的行为。

字符串长度

默认情况下,字符串长度为 6 个字符。您可以将其更改为任何长度。请注意,您可能还需要更改宽度,它不是自动计算的。

'length' => 6

宽度和高度

默认情况下,宽度和高度为 200px x 50px。您可以将其更改为任何其他大小。

'width' => 200,
'height' => 50

大小写敏感

默认情况下,大小写验证已启用。将其更改为 false 以禁用它。

'case_sensitive' => true

字母大小写

如果您想验证码只显示大写字母、小写字母或混合。

'case' => 'upper' //For upper case letters only
'case' => 'lower' //For lower case letters only
'case' => 'mixed' //For both upper and lower case

显示字母/数字

如果您想显示只有字母的验证码

'letters' => true,
'numbers' => false

如果您想显示只有数字的验证码

'letters' => false,
'numbers' => true

如果您想显示字母和数字的组合验证码

'letters' => true,
'numbers' => true

字符角度

默认情况下,字符角度为 15。这将生成字符角度在 0 到 15 度之间的验证码。将其更改为您想要的任何值。如果您想以“直线”方式显示字符,只需将此值设置为 0(零)即可。

'angle' => 15

间隔

这是字符之间的间隔。默认为 30。 间隔越大,字符越分散

'separation' => 30,

背景网格

默认情况下,背景显示 20 条垂直线和 5 条水平线(每 10 像素一条)。您可以显示任意数量的线条。

'h_lines' => 5, //Horizontal lines
'v_lines' => 20 //Vertical lines

颜色

颜色必须以 RGB 表示法 [rrr,ggg,bbb] 提供。

背景颜色

默认为 250,250,250(几乎为白色)

'background' => [250, 250, 250]
线条颜色

默认为220,220,220(非常浅灰色)

'line_color' => [220, 220, 220]
字体颜色

这是一个选择列表的数组。您可以添加任意多的颜色,字符将以这些颜色随机渲染。

'colors' => [
    [0, 83, 160],
    [33, 125, 211],
    [30, 134, 232],
    [11, 72, 130],
    [13, 119, 219],
    [0, 102, 150],
    [51, 113, 142],
],

字体

此包与 TrueType (.ttf) 字体 兼容。

已经提供了四种字体选择:Prototype(默认),ImpactBrianJamesSpinwerad。所有这些都要感谢 1001freefonts

Prototype
'font' => 'Prototype' //Ignore .ttf extension

Prototype

Impact
'font' => 'Impact' //Ignore .ttf extension

Impact

BrianJames
'font' => 'BrianJames' //Ignore .ttf extension

BrianJames

Spinwerad
'font' => 'Spinwerad' //Ignore .ttf extension

Spinwerad

字体大小

默认字体大小为 30px。可以更改为您想要的任何大小。

'size' => 30

图片质量

默认情况下,图片质量为100,我建议保持这个设置。

'quality' => 100,