GithubHelp home page GithubHelp logo

zensec / captcha-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eusonlito/captcha

0.0 2.0 0.0 370 KB

A new simple and easy-to-implement captcha package.

License: MIT License

PHP 100.00%

captcha-1's Introduction

Easy Captcha :)

Build Status Latest Stable Version Total Downloads License

A new simple and easy-to-implement captcha package.

Installation with Composer

{
    "require": {
        "eusonlito/captcha": "1.0.*"
    }
}

Demos

Default Captcha Only one font Large Captcha Short Captcha With Background Custom Letters With Noise Only Noise Points Only Noise Lines

Usage

Template

<?php use Eusonlito\Captcha\Captcha; ?>

<div class="form-group">
    <img src="<?= Captcha::source($LETTERS_COUNT, $WIDTH, $HEIGHT); ?>" class="img-responsive" />
    <input type="text" name="<?= Captcha::sessionName(); ?>" value="" class="form-control" />

    ... or ...

    <?= Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); ?>
    <input type="text" name="<?= Captcha::sessionName(); ?>" value="" class="form-control" />

    ... or ...

    <?= Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT, array('class' => 'img-responsive')); ?>
    <input type="text" name="<?= Captcha::sessionName(); ?>" value="" class="form-control" />

    ... or ...

    <?= Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); ?>
    <?= Captcha::input(array('class' => 'form-control')); ?>

    ... or ...

    <?= Captcha::img(array($LETTERS_MIN, $LETTERS_MAX) $WIDTH, $HEIGHT); ?>
    <?= Captcha::input(array('class' => 'form-control')); ?>
</div>

If you are using an environment without sessions, you must add Captcha::sessionStart() before any html output (Controller).

Checking

<?php
use Eusonlito\Captcha\Captcha;

function validate()
{
    if (!Captcha::check()) {
        throw new Exception('Captcha text is not correct');
    }
}

That's all!

Laravel Usage

<?php
# config/app.php

return [
    ...

    'aliases' => [
        ...

        'Captcha' => 'Eusonlito\Captcha\Captcha',

        ...
    ]
];

Now you will have a Captcha class available on your controllers and views.

Print Options

<?php
use Eusonlito\Captcha\Captcha;

# Simple usage with fixed word length
Captcha::source($LETTERS_COUNT, $WIDTH, $HEIGHT); # Print base64 source image code

# Define min and max word length
Captcha::source(array($LETTERS_MIN, $LETTERS_MAX), $WIDTH, $HEIGHT); # Print base64 source image code

# Same using img tag
Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); # Print img tag
Captcha::img(array($LETTERS_MIN, $LETTERS_MAX), $WIDTH, $HEIGHT); # Print img tag

# Img tag with parameters
Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT, array('class' => 'img-responsive')); # Print img tag with class attribute

# Simple input tag print
Captcha::input(); # Print input tag

# Input tag with parameters
Captcha::input(array('class' => 'form-control')); # Print input tag with class attribute

Custom Setup

All custom settings will be defined before img, source or check methods calls.

<?php
use Eusonlito\Captcha\Captcha;

# Define a unique font to use (only .ttf)
Captcha::setFont(__DIR__.'/../fonts/couture-bold.ttf'); # string or array

# Add fonts to repository (only .ttf)
Captcha::addFont(array(
    __DIR__.'/../fonts/couture-bold.ttf',
    __DIR__.'/../fonts/brush-lettering-one.ttf'
));

# Set custom rgb background. Default is 255, 255, 255
Captcha::setBackground([120, 120, 120]);

# Set custom hex background.
Captcha::setBackground('#FFF000');

# Set transparent background.
Captcha::setBackground('transparent');

# Set custom rgb font color. Default is 115, 115, 115
Captcha::setColor([50, 50, 50]);

# Set custom hex color.
Captcha::setColor('#000FFF');

# Set custom padding to captcha image (approximate). Default is 0.4
Captcha::setPadding(20); // Fixed value in pixels
Captcha::setPadding(0.4); // Percent value

# Set image noise. Default is without noise
Captcha::setNoise($POINTS, $LINES); // Fixed points and lines noise
Captcha::setNoise(array($POINTS_MIN, $POINTS_MAX), array($LINES_MIN, $LINES_MAX)); // Variable points and lines noise
Captcha::setNoise(null, array($LINES_MIN, $LINES_MAX)); // Avoid points noise
Captcha::setNoise(array($POINTS_MIN, $POINTS_MAX), null); // Avoid lines noise

# Set custom available letters. Default are 'ABCDEFGHJKLMNPRSTUVWXYZ'
Captcha::setLetters('ABCDE3456');

# Set custom session name captcha storage (captcha string is stored crypted). Default is 'captcha-string'
Captcha::sessionName('my-captcha');

# Enable session before use on non session environments
Captcha::sessionStart();

Enjoy!

captcha-1's People

Contributors

eusonlito avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.