PHPackages                             michele-angioni/phalcon-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. michele-angioni/phalcon-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

michele-angioni/phalcon-auth
============================

A library which provide you with simple authentication.

v0.1(10y ago)57.4k2MITPHPPHP &gt;=5.5

Since May 8Pushed 10y ago2 watchersCompare

[ Source](https://github.com/micheleangioni/phalcon-auth)[ Packagist](https://packagist.org/packages/michele-angioni/phalcon-auth)[ RSS](/packages/michele-angioni-phalcon-auth/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Phalcon Auth
============

[](#phalcon-auth)

[![License](https://camo.githubusercontent.com/fe4dd7e12e7d9394bd65a10a64f399d194e66cfa2998673b74a2b899e52eceed/68747470733a2f2f706f7365722e707567782e6f72672f6d696368656c652d616e67696f6e692f7068616c636f6e2d617574682f6c6963656e7365)](https://packagist.org/packages/michele-angioni/phalcon-auth)[![Latest Stable Version](https://camo.githubusercontent.com/b878a9b3229aafd7a5f3d5ed73b8dbd27a70d4a95aeb737667059f1ba09dc5cb/68747470733a2f2f706f7365722e707567782e6f72672f6d696368656c652d616e67696f6e692f7068616c636f6e2d617574682f762f737461626c65)](https://packagist.org/packages/michele-angioni/phalcon-auth)[![Latest Unstable Version](https://camo.githubusercontent.com/97076feeed0ee83e050148722148995a88d8e4c12a1add6b32375d09d63e3e19/68747470733a2f2f706f7365722e707567782e6f72672f6d696368656c652d616e67696f6e692f7068616c636f6e2d617574682f762f756e737461626c65)](https://packagist.org/packages/michele-angioni/phalcon-auth)[![Build Status](https://camo.githubusercontent.com/e232eadbcb5d01c7f6dc5cf085f1ee6d6aa845fe02c5620f267792134be88e16/68747470733a2f2f7472617669732d63692e6f72672f6d696368656c65616e67696f6e692f7068616c636f6e2d617574682e737667)](https://travis-ci.org/micheleangioni/phalcon-auth)

Introduction
------------

[](#introduction)

Phalcon Auth provides you a fast way to register and authenticate your users.

Every application, every website needs its own User model with its own properties and methods. Phalcon Auth does not force you to use its own model nor create useless overhead by defining relationships with other models. You are a Phalcon user, so speed and simplicity is what you are looking for.

So, Phalcon Auth just requires your own User model to satisfy some requirements by implementing its interface. Basically, it just need a few methods:

- getId() : (int)
- getEmail() : (string)
- getPassword() : (string)
- setPassword($password) : (bool)
- getConfirmationCode() : (string)
- setConfirmationCode($confirmationCode) : (bool)
- confirm() : (bool)
- isConfirmed() : (bool)
- isBanned() : (bool)

Furthermore, if you want to use the "remember me" feature, the following remember token getter and setter are required

- getRememberToken() : (string)
- setRememberToken($token) : (bool)

Installation
------------

[](#installation)

Phalcon Auth can be installed through Composer, just include `"michele-angioni/phalcon-auth": "~0.1"` to your composer.json and run `composer update` or `composer install`.

Usage
-----

[](#usage)

Let's say you have a `MyApp\Users` model you want to make authenticatable. The way to do it is very simple, i.e. it must implement the `MicheleAngioni\PhalconAuth\Contracts\AuthableInterface` or, if you want to use the remember me feature, the `MicheleAngioni\PhalconAuth\Contracts\RememberableAuthableInterface`.

An example can be the this one:

```
namespace MyApp;

class Users extends \Phalcon\Mvc\Model implements \MicheleAngioni\PhalconAuth\Contracts\RememberableAuthableInterface
{
    protected $id;

    protected $banned;

    protected $confirmation_code;

    protected $confirmed;

    protected $email;

    protected $password;

    protected $remember_token;

    public function getId()
    {
        return $this->id;
    }

    public function getConfirmationCode()
    {
        return $this->confirmation_code;
    }

    public function isConfirmed()
    {
        return (bool)$this->confirmed;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
        return true;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = $password;
        return true;
    }

    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($token)
    {
        $this->remember_token = $token;
        return true;
    }

    public function isBanned()
    {
        return (bool)$this->banned;
    }
}

```

We can then define the `auth` service in the Phalcon container in application bootstrap file, and pass the `MyApp\Users` model to it. This way, it will be easily retrievable for example in the controllers

```
/**
 * Authentication
 */
$di->setShared('auth', function () {
    return \MicheleAngioni\PhalconAuthAuth(new \MyApp\Users());
});

```

Now we can define a simple controller for User registration, confirmation, login, logout and password reset:

```
