2017 © Pedro Peláez
 

yii2-extension yii2-remember-me

Enhanced Remember Me

image

listfixer/yii2-remember-me

Enhanced Remember Me

  • Saturday, February 4, 2017
  • by Michael-Labriola
  • Repository
  • 3 Watchers
  • 3 Stars
  • 167 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

yii2-remember-me

This extension replaces the standard "Remember Me" identity cookie functionality of Yii2 with something similar to what is described here: http://jaspan.com/improved_persistent_login_cookie_best_practice, (*1)

When a user requests "Remember Me" during login, a new identity cookie is created for that user for that browser/computer. The cookie contains three things which are also stored in a database table: (1) a Cookie ID, which is the record number in the identity cookie database table, (2) A Cookie Key, which is the "password" for that particular cookie, and (3) A User Key, which is the "password" for the associated user. When I say "password", it is a random string, not an actual password. The database stores some other information, including the User ID number., (*2)

Each time a user restarts their browser and is authenticated using this system, all three items are checked against the database. If the contents of the cookie match a record in the database, the user gains access to the system and a new User Key is generated. The new User Key is stored in the database and in the identity cookie., (*3)

If a particular user uses three different computers, then there will be three different records in the database, one for each cookie. When each of these cookies is used to authenticate a user, the User Key for that particular cookie is regenerated, leaving the other identity cookie User Keys unchanged. This allows a particular user to have "Remember Me" functionality on multiple computers, yet still have their User Key change with each use., (*4)

If someone copies or steals an identity cookie, whichever cookie is used first (the original or the copy) will still work, since there is no way to determine which is the original and which is the copy. The User Key will match and a new User Key will be generated. Once the other cookie is used, the User Key will have already changed. The Cookie ID and Cookie Key will match, but the User Key will not, thus indicating that more than one identity cookies exists with this Cookie ID and Cookie Key. The database record is then deleted, thus disabling all cookies with this Cookie ID and Cookie Key., (*5)

To create the database table, use this command from your Yii2 application base directory:, (*6)

php ./yii migrate --migrationPath=@vendor/listfixer/yii2-remember-me/migrations, (*7)

The database migration assumes that you have a table called "user" with an integer primary key called "id"., (*8)

To enable this extension, edit your configuration file to include this component information:, (*9)

'components' => [ 'user' => [ 'class' => 'listfixer\remember\RememberMe', 'identityClass' => /* you should already have something here */, 'enableAutoLogin' => true, ] ], (*10)

When a user changes their password, you can configure your system to disable all existing identity cookies for that user by invoking this method:, (*11)

\listfixer\remember\models\UserIdentityCookie::deleteUserCookies( $this->id );, (*12)

If you are using the Yii2 Advanced template, then this should be added to setPassword() in common/models/User.php., (*13)

The Versions

04/02 2017

dev-master

9999999-dev

Enhanced Remember Me

  Sources   Download

BSD-3-Clause

The Requires

 

by Michael Labriola

yii2 cookie login remember

04/02 2017

v1.0.1

1.0.1.0

Enhanced Remember Me

  Sources   Download

BSD-3-Clause

The Requires

 

by Michael Labriola

yii2 cookie login remember

28/01 2017

v1.0

1.0.0.0

Enhanced Remember Me

  Sources   Download

BSD-3-Clause

The Requires

 

by Michael Labriola

yii2 cookie login remember