2017 © Pedro Peláez
 

library auth

Authentication library

image

objectiveweb/auth

Authentication library

  • Sunday, May 27, 2018
  • by guigouz
  • Repository
  • 2 Watchers
  • 3 Stars
  • 188 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

Auth Build Status

Authentication Library, (*1)

Setup

Setup the auth dependency on your project's composer.json, then run composer update, (*2)

   "require": {
       "objectiveweb/auth": "~0.1"
   }

Auth initialization

Create a new $auth instance, passing the appropriate parameters, (*3)

// Auth depends on PDO
$pdo = new PDO($dsn);

$auth = new Auth($pdo, [
    'session_key' => 'ow_auth',
    'table' => 'ow_auth',
    'id' => 'id',
    'username' => 'username',
    'password' => 'password',
    'token' => NULL,
    'created' => NULL,
    'last_login' => NULL
]);

Parameters

  • 'session_key', (*4)

    Key used for $_SESSION storage, defaults to 'ow_auth', (*5)

  • 'table', (*6)

    Database table which stores users, defaults to 'ow_auth', (*7)

  • 'id', (*8)

    Primary key of the user table, defaults to 'id', (*9)

  • 'username', (*10)

    Username field on the user table, defaults to 'username', (*11)

  • 'password', (*12)

    Password field on the user table, defaults to 'password',, (*13)

  • 'token', (*14)

    Optional CHAR(32) field to store a random token, (*15)

  • 'created', (*16)

    Optional DATETIME field to store the accounts creation date, (*17)

  • 'last_login', (*18)

    Optional DATETIME field to store the last successful login date, (*19)

Usage

# register user
try {
    $user = $auth->register('username', 'password');
}
catch(\Exception $ex) {
    printf('DB Error creating user: %s', $ex->getMessage());
}

# login user
try {
    $user = $auth->login('username', 'password');
}
catch(PasswordMismatchException $ex) {
    printf("Password mismatch");
}
catch(UserException $ex) {
    printf("Error logging in: %s", $ex->getMessage());
}

# check if the user is logged in
if($auth->check()) {
    // user is logged in
}
else {
    // user is not logged in
};

# retrieve the current user from the session
try {
    $user = $auth->user();
}
catch(UserException $ex) {
    printf("User not logged in");
}

# logout user
$auth->logout();

Store additional data when registering a user

$user = $auth->register('username', 'password', [
    'email' => 'someone@somewhere',
    'displayName' => 'Test User'
]);

Generating a password reset token

When the token parameter is enabled in initialization, (*20)

$token = $auth->update_token($username);

// send $token to user, then later
try {
    $auth->passwd_reset($token, $new_password);
}
catch(UserException $ex) {
    printf('Invalid token provided');
}

Updating user data

$auth->update($username, [ 'email' => 'new@email.com' ]);

The Versions

27/05 2018

dev-oauth2

dev-oauth2

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

12/02 2018

dev-oauth-acl

dev-oauth-acl

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

12/08 2016

dev-master

9999999-dev

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

12/08 2016

v0.1.13

0.1.13.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

12/08 2016

v0.1.12

0.1.12.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

30/10 2015

v0.1.11

0.1.11.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

30/10 2015

v0.1.10

0.1.10.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

13/10 2015

v0.1.9

0.1.9.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

13/10 2015

v0.1.8

0.1.8.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

11/10 2015

v0.1.7

0.1.7.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

10/10 2015

v0.1.6

0.1.6.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

09/10 2015

v0.1.5

0.1.5.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

09/10 2015

v0.1.4

0.1.4.0

Authentication library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

18/02 2015

v0.1.3

0.1.3.0

Authentication library

  Sources   Download

MIT

The Development Requires

18/02 2015

v0.1.2

0.1.2.0

Authentication library

  Sources   Download

MIT

The Development Requires

18/02 2015

v0.1.1

0.1.1.0

Authentication library

  Sources   Download

MIT

The Development Requires

17/02 2015

v0.1.0

0.1.0.0

Authentication library

  Sources   Download

MIT

The Development Requires