Giter Site home page Giter Site logo

pageon / expiringtoken Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 24 KB

A cryptographically safe token with a build in customizable expiration date

Home Page: https://pageon.github.io/ExpiringToken/

License: MIT License

PHP 100.00%
forgot-password password-reset token tokens php php-7 expiration token-authentication

expiringtoken's Introduction

Expiring Token

Build Status License Code Coverage Scrutinizer Code Quality

The expiring token generates a random token of 128 characters with an expiration date.

The token uses base64 but the length is calculated so that it is url safe, so no padding with the = character.

The actual token is generated with random_bytes with a length of 32

Installation

You can add this library as a local, per-project dependency to your project using Composer:

composer require pageon/expiring-token

Public api

ExpiringToken::create

You can create a new token this way. It accepts a DateInterval as optional parameter to set a different expiration date.

The default expiration date is 3 days.

ExpiringToken::fromString

Used to create an instance of the token from the string representation

ExpiringToken::__toString

This turns the class instance into the string version of the token when the instance is used as or cast to a string.

ExpiringToken::validateAgainst

This can be used to validate the current token against an other token

  • When the tokens maths this method will return true
  • An InvalidToken exception will be thrown if the tokens don't match
  • An TokenHasExpired exception will be thrown if the token has expired

ExpiringToken::hasExpired

Returns a bool indicating if the current token has expired

ExpiringToken::getExpiresOn

Can be used to get the expiration date of the token

expiringtoken's People

Contributors

carakas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.