Giter Club home page Giter Club logo

cat's Introduction

CAT a.k.a Casual Authenticaiton Token

About it

CAT is create temporary token securely and easily.

How it works?

When you create token, the string will be look like this

ewogICJ1c2VybmFtZSI6ICJsaWxsNzQiLAogICJhY2wiOiAibG9naW4iLAogICJpcGFkciIgOiAiMTI3LjAuMC4xIiwKICAiZXhwaXJlIiA6ICIxNTM3ODg4NjY4Igp9.210939ec8da100a52e41861bcf7393de6ca86f6357a3c5078f5410bb14c82111

It just contain payload and hmac sha256 for verifying.

That means you should set salt variable randomly and you must manage your salt variable.

API Document

Functions

Type Name Args Function
Object Constructor __construct $defsalt (null) Object Constructor
String CreateToken $payload, $salt (null) Creating Token
Bool VerifyToken $data, $acl, $ref, $salt (null) Verifying Token

You might be confused, Let me explain.

Example

Creating Token

$cat = new CAT("Salt!");

$arr = array(

                    'username' => $username,

                    'acl' => $acl,

                    'ipadr' => $_SERVER["REMOTE_ADDR"],

                    'expire' => time() + 600

);

$data = $cat -> CreateToken(json_encode($arr));

setcookie($coookie_name, $data, time() + 600, "/", "", null, true);

Verifying Token

$cat = new CAT(getProperty("salt"));

if($cat -> VerifyToken($_COOKIE["token"], $acl, $ref)) {

โ€‹	return true;

}

return false;

Security Tips

When you save token into cookie, you must be save as http only cookie.

Otherwise, Attackers can try XSS.

cat's People

Stargazers

 avatar  avatar

Watchers

 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.