2017 © Pedro Peláez
 

library token

Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based

image

malahierba-lab/token

Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based

  • Sunday, October 25, 2015
  • by malahierba
  • Repository
  • 1 Watchers
  • 3 Stars
  • 159 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Laravel Token

A tool for easy public token implementation in some common tasks: password reset, account activation, etc. In general, when need to send a token through mail (for example). We are developed with Laravel 5.x in mind., (*1)

Installation

Add in your composer.json:, (*2)

{
    "require": {
        "malahierba-lab/token": "~1.0"
    }
}

Then you need run the composer update command., (*3)

How Work

The tokens are save using Laravel Cache Facade, so you don't need a table in your database (unless you are using the database cache as driver), so... you don't need alter your current database, and tokens expire automatically without headaches :), (*4)

Use

Important: For documentation purposes, in the examples below, always we assume than you import the library into your namespace using use Malahierba\Token\Token;, (*5)

You can generate a token for any model (Eloquent/Model) in your project. In this examples below we are using the User Model, but you can use the Model than you need., (*6)

1.- Make a Token Instance, (*7)

//Get a Model Instance... in this case, a User instance.
$user = User::find(1);

// Create a password reset token instance
// 'password reset' is just a example... you can use the string than you want :)
// so.. if you want a token named 'my token type' just use it as second parameter. No predefined types.
$token = new Token($user, 'password reset');

//You can define the duration, in minutes, until the token expire. Default is 60.
//This example set 15 minutes to expire the token
$token = new Token($user, 'password reset', 15);

//Also you can define the number of chars for token. Default is 48
//This example set token length in 32 chars (and use the default minutes to expire)
$token = new Token($user, 'password reset', null, 32);

//This example set 15 minutes to expire the token and token length in 32 chars
$token = new Token($user, 'password reset', 15, 32);

2.- Get the Token string, (*8)

$token_str = $token->get();

If no previous token exists (or previous token is expired), then you will get a new randomly generated string. If previous token exists (and is not expired yet) then you get that token., (*9)

3.- Check the Token, (*10)

You can validate a token entered by an user or when come from url (for example if you mail a link for password reset with the token as parameter):, (*11)

if ($token->check($string))
    // code for token validated

4.- Delete the Token, (*12)

When you don't need the token anymore (for example, your user already setup a new password in password reset lifecycle) you can delete it:, (*13)

$token->delete();

The delete method no destroy the token instance, just delete the old token string. If you run $token->get() you will receive a new token for same user (and same type) because the instance is the same., (*14)

Licence

This project has MIT licence. For more information please read LICENCE file., (*15)

The Versions

25/10 2015

dev-master

9999999-dev

Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based

  Sources   Download

MIT

The Requires

 

laravel cache token password reset

25/10 2015

1.0.1

1.0.1.0

Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based

  Sources   Download

MIT

The Requires

 

laravel cache token password reset

24/10 2015

1.0

1.0.0.0

Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based

  Sources   Download

MIT

The Requires

 

laravel cache token password reset