2017 © Pedro Peláez
 

library temp-token

A nice and simple library which allows you to generate a random token with an accompanying expiration date - perfect for creating 'forgotten password' URL's, however the temporary token could be used for anything.

image

mattkirwan/temp-token

A nice and simple library which allows you to generate a random token with an accompanying expiration date - perfect for creating 'forgotten password' URL's, however the temporary token could be used for anything.

  • Sunday, February 3, 2013
  • by mattkirwan
  • Repository
  • 0 Watchers
  • 5 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Temp-Token - A Simple PHP Temporary Token Generator

Why?

I needed a temporary password reset token generating when a user 'forgot their password'. Although a nice feature, pulling in dependencies for storage seemed overkill and decided to just spin up a quick library that generated a very unique token (it can be made even more unique via a 'salt' - something unique to that instance) and a expiration DateTime object for that token., (*1)

I suppose you could use it for any scenario requiring a temporary, guaranteed to expire token - my use case was simply a password reset link token., (*2)

What exactly?

Basically this package allows you to generate two things: 1) A unique token 2) An expiration time for the above token, (*3)

For ease you can simply store these inside a users table once a password has been reset, send the user a link to the unique url - and assuming the token matches and hasn't expired let them reset their password., (*4)

Installation:

This library is published on packagist.org, to install you will need the following in your projects composer.json:, (*5)

{
    "require": {
        "mattkirwan/temp-token": "1.0.*"
    },  
    "minimum-stability": "dev"
}

Once you have that, simply run:, (*6)

php composer.phar update

and then use..., (*7)

Usage:

require './vendor/autoload.php';

// Instantiate a new TempToken object
$temp_token = new MattKirwan\TempToken\TempToken();

// Optionally set a unique salt (maybe a username?) for more randomness in the token
$temp_token->set_unique_salt($username);

// Optionally set the token lifetime in seconds - defaults to 1 hour (3600 secs)
$temp_token->set_token_lifetime_secs(7200);

// Optionally set a date format for the token expiration DateTime object
$temp_token->set_date_format('d-m-Y');

// Generates a new token and token expiration
$temp_token->generate_token();

// Retrieve the token
$token = $temp_token->get_token();

// Retrieve a token expiration DateTime
$token_expires = $temp_token->get_token_expiration();

The Versions

03/02 2013

dev-master

9999999-dev

A nice and simple library which allows you to generate a random token with an accompanying expiration date - perfect for creating 'forgotten password' URL's, however the temporary token could be used for anything.

  Sources   Download

GPL-2.0

generator password token generate create temporary temp user token forget forgot password url password link

03/02 2013

1.0.7

1.0.7.0

A nice and simple library which allows you to generate a random token with an accompanying expiration date - perfect for creating 'forgotten password' URL's, however the temporary token could be used for anything.

  Sources   Download

GPL-2.0

generator password token generate create temporary temp user token forget forgot password url password link

02/02 2013

1.0.6

1.0.6.0

A nice and simple library which allows you to generate a random token with an accompanying expiration date - perfect for creating 'forgotten password' URL's, however the temporary token could be used for anything.

  Sources   Download

GPL-2.0

generator password token generate create temporary temp user token forget forgot password url password link

02/02 2013

1.0.5

1.0.5.0

  Sources   Download

02/02 2013

1.0.4

1.0.4.0

  Sources   Download

29/01 2013

1.0.3

1.0.3.0

  Sources   Download

29/01 2013

1.0.2

1.0.2.0

  Sources   Download

29/01 2013

1.0.1

1.0.1.0

  Sources   Download

29/01 2013

1.0.0

1.0.0.0

  Sources   Download