{"id":37234157,"url":"https://github.com/micheleangioni/phalcon-auth","last_synced_at":"2026-01-15T03:57:47.285Z","repository":{"id":62528170,"uuid":"58230637","full_name":"micheleangioni/phalcon-auth","owner":"micheleangioni","description":"Easy user validation for Phalcon 2/3.","archived":false,"fork":false,"pushed_at":"2016-05-09T14:06:26.000Z","size":53,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-26T10:33:23.796Z","etag":null,"topics":["authentication","phalcon","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micheleangioni.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-06T19:35:50.000Z","updated_at":"2021-05-05T13:47:08.000Z","dependencies_parsed_at":"2022-11-02T10:45:40.301Z","dependency_job_id":null,"html_url":"https://github.com/micheleangioni/phalcon-auth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/micheleangioni/phalcon-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleangioni%2Fphalcon-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleangioni%2Fphalcon-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleangioni%2Fphalcon-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleangioni%2Fphalcon-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micheleangioni","download_url":"https://codeload.github.com/micheleangioni/phalcon-auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleangioni%2Fphalcon-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","phalcon","php"],"created_at":"2026-01-15T03:57:46.599Z","updated_at":"2026-01-15T03:57:47.277Z","avatar_url":"https://github.com/micheleangioni.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phalcon Auth\n\n[![License](https://poser.pugx.org/michele-angioni/phalcon-auth/license)](https://packagist.org/packages/michele-angioni/phalcon-auth)\n[![Latest Stable Version](https://poser.pugx.org/michele-angioni/phalcon-auth/v/stable)](https://packagist.org/packages/michele-angioni/phalcon-auth)\n[![Latest Unstable Version](https://poser.pugx.org/michele-angioni/phalcon-auth/v/unstable)](https://packagist.org/packages/michele-angioni/phalcon-auth)\n[![Build Status](https://travis-ci.org/micheleangioni/phalcon-auth.svg)](https://travis-ci.org/micheleangioni/phalcon-auth)\n\n## Introduction\n\nPhalcon Auth provides you a fast way to register and authenticate your users. \n\nEvery application, every website needs its own User model with its own properties and methods. \nPhalcon Auth does not force you to use its own model nor create useless overhead by defining relationships with other models. \nYou are a Phalcon user, so speed and simplicity is what you are looking for.\n\nSo, Phalcon Auth just requires your own User model to satisfy some requirements by implementing its interface. \nBasically, it just need a few methods: \n\n- getId() : (int)\n- getEmail() : (string)\n- getPassword() : (string)\n- setPassword($password) : (bool)\n- getConfirmationCode() : (string)\n- setConfirmationCode($confirmationCode) : (bool)\n- confirm() : (bool) \n- isConfirmed() : (bool)\n- isBanned() : (bool)\n\nFurthermore, if you want to use the \"remember me\" feature, the following remember token getter and setter are required\n \n - getRememberToken()  : (string)\n - setRememberToken($token) : (bool)\n\n## Installation\n \nPhalcon 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`.\n\n## Usage\n\nLet's say you have a `MyApp\\Users` model you want to make authenticatable.\nThe 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`.\n\nAn example can be the this one:\n\n    namespace MyApp;\n\n    class Users extends \\Phalcon\\Mvc\\Model implements \\MicheleAngioni\\PhalconAuth\\Contracts\\RememberableAuthableInterface\n    {\n        protected $id;\n        \n        protected $banned;\n    \n        protected $confirmation_code;\n    \n        protected $confirmed;\n    \n        protected $email;\n    \n        protected $password;\n    \n        protected $remember_token;\n    \n        public function getId()\n        {\n            return $this-\u003eid;\n        }\n    \n        public function getConfirmationCode()\n        {\n            return $this-\u003econfirmation_code;\n        }\n    \n        public function isConfirmed()\n        {\n            return (bool)$this-\u003econfirmed;\n        }\n    \n        public function getEmail()\n        {\n            return $this-\u003eemail;\n        }\n        \n        public function setEmail($email)\n        {\n            $this-\u003eemail = $email;\n            return true;\n        }\n    \n        public function getPassword()\n        {\n            return $this-\u003epassword;\n        }\n        \n        public function setPassword($password)\n        {\n            $this-\u003epassword = $password;\n            return true;\n        }\n    \n        public function getRememberToken()\n        {\n            return $this-\u003eremember_token;\n        }\n    \n        public function setRememberToken($token)\n        {\n            $this-\u003eremember_token = $token;\n            return true;\n        }\n        \n        public function isBanned()\n        {\n            return (bool)$this-\u003ebanned;\n        }\n    }\n\nWe can then define the `auth` service in the Phalcon container in application bootstrap file, and pass the `MyApp\\Users` model to it.\nThis way, it will be easily retrievable for example in the controllers\n\n    /**\n     * Authentication\n     */\n    $di-\u003esetShared('auth', function () {\n        return \\MicheleAngioni\\PhalconAuthAuth(new \\MyApp\\Users());\n    });\n\nNow we can define a simple controller for User registration, confirmation, login, logout and password reset:\n\n    \u003c?php\n    \n    namespace MyApp\\Controllers;\n    \n    use Phalcon\\Mvc\\Controller;\n    \n    class AuthController extends Controller\n    {\n\n        public function registerAction()\n        {\n            $email = $this-\u003erequest-\u003egetPost('email);\n            $password = $this-\u003erequest-\u003egetPost('password);\n            \n            // [..] Data validation\n        \n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Register the new user\n            \n            try {\n                $user = $auth-\u003eregister($email, $password);\n            } catch (\\Exception $e) {\n                if ($e instanceof \\UnexpectedValueException) {\n                    // The email has already been taken, handle the exception\n                } else {\n                    // Handle other exception\n                }\n            }\n    \n            [...] // It is up to you to comunicate the confirmation code to the user\n        }\n        \n        public function confirmAction($idUser, $confirmationCode)\n        {\n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Confirm the user\n            \n            try {\n                $user = $auth-\u003econfirm($idUser, $confirmationCode);\n            } catch (\\Exception $e) {\n                if ($e instanceof \\EntityNotFoundException) {\n                    // User not found. Handle the exception\n                } else {\n                    // Wrong confirmation code. Handle other exception\n                }\n            }\n    \n            [...]\n        }\n        \n        public function loginAction()\n        {\n            $email = $this-\u003erequest-\u003egetPost('email);\n            $password = $this-\u003erequest-\u003egetPost('password);\n            \n            // [..] Data validation\n        \n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Perform login\n            \n            try {\n                $user = $auth-\u003eattemptLogin($email, $password);\n            } catch (\\Exception $e) {\n                if ($e instanceof \\MicheleAngioni\\PhalconAuth\\Exceptions\\EntityBannedException) {\n                    // The user is banned. Handle exception\n                } else {\n                    // Handle wrong credentials exception\n                }\n            }\n    \n            [...]\n        }\n        \n        public function logoutAction()\n        {\n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Perform logout\n            $auth-\u003elogout();\n    \n            [...]\n        }\n        \n        public function getPasswordTokenAction($idUser)\n        {\n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Get the reset password token\n            \n            try {\n                $token = $auth-\u003egetResetPasswordToken($idUser);\n            } catch (\\Exception $e) {\n                if ($e instanceof \\MicheleAngioni\\PhalconAuth\\Exceptions\\EntityNotFoundException) {\n                    // User not found. Handle the exception\n                } else {\n                    // Authable entity is not confirmed yet, it cannot reset the password. Handle the exception\n                }\n            }\n    \n            [...]\n        }\n        \n        public function resetPasswordAction($idUser, $resetToken)\n        {\n            $password = $this-\u003erequest-\u003egetPost('newPassword);\n                        \n            // [..] Data validation\n        \n            // Retrieve Auth Service\n            $auth = $this-\u003egetDI()-\u003eget('auth');\n            \n            // Get the reset password token\n            \n            try {\n                $token = $auth-\u003eresetPassword($idUser, $resetToken, $newPassword);\n            } catch (\\Exception $e) {\n                if ($e instanceof \\MicheleAngioni\\PhalconAuth\\Exceptions\\EntityNotFoundException) {\n                    // User not found. Handle the exception\n                } else {\n                    // Authable entity is not confirmed or the token is wrong. Handle the exception\n                }\n            }\n    \n            [...]\n        }\n    }\n\nAfter the login, the user id and email will be saved in the session. \n\n### Advanced user registration\n\nWhen registering a new user, you can pass an array of other parameters and an array of parameters you want to be unique in your user table\n\n    $auth-\u003eregister($email, $password, $parameters = [], $uniqueParameters = [], $addConfirmationCode = true));\n   \n### Customize login\n\nYou can customize the login settings by modifying the other method parameters\n\n    $auth-\u003eattemptLogin($email, $password, $saveSession = true, $rememberMe = false);\n    \n### Logging in after the \"remember me\" has been set\n\nAfter authenticating with a \"remember me\", just use the following method\n\n    if ($auth-\u003ehasRememberMe()) {\n        $auth-\u003eloginWithRememberMe();\n    }\n\n### Retrieve the logged user info from the session\n\n    $auth-\u003egetIdentity(); // Returns an array with 'id' and 'email' keys\n    \n### Retrieve the authenticated user\n\n    $auth-\u003egetAuth();\n    \n### Manually login through user id\n\n    $auth-\u003eauthById($id);\n\n### Customize the behaviour\n    \nWhen defining the Auth service, you can can pass an options array. Below all available options are listed\n\n        /**\n         * Authentication\n         */\n         $options = [\n            'rememberMeDuration' =\u003e 1096000 // Optional, default: 604800 (1 week)\n         ];\n         \n        $di-\u003eset('auth', function () {\n            return \\MicheleAngioni\\PhalconAuthAuth(new \\MyApp\\Users(), $options);\n        });\n    \n## Contribution guidelines\n\nPhalcon Auth follows PSR-1, PSR-2 and PSR-4 PHP coding standards, and semantic versioning.\n\nPull requests are welcome.\n\n## License\n\nPhalcon Auth is free software distributed under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheleangioni%2Fphalcon-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicheleangioni%2Fphalcon-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheleangioni%2Fphalcon-auth/lists"}