{"id":19458878,"url":"https://github.com/leafsphp/auth","last_synced_at":"2025-08-22T10:33:16.124Z","repository":{"id":39642805,"uuid":"408121853","full_name":"leafsphp/auth","owner":"leafsphp","description":"🔐 Leaf PHP auth module","archived":false,"fork":false,"pushed_at":"2025-06-24T01:40:18.000Z","size":218,"stargazers_count":6,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"v4.x","last_synced_at":"2025-06-30T19:50:26.661Z","etag":null,"topics":["authentication","leafphp","php"],"latest_commit_sha":null,"homepage":"https://leafphp.dev/modules/auth/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafsphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"leaf","github":"leafsphp"}},"created_at":"2021-09-19T12:30:56.000Z","updated_at":"2025-06-24T01:40:22.000Z","dependencies_parsed_at":"2022-08-28T10:50:43.687Z","dependency_job_id":"f878e5cb-dd8a-46cd-9dc3-8b6fc76169e8","html_url":"https://github.com/leafsphp/auth","commit_stats":{"total_commits":59,"total_committers":2,"mean_commits":29.5,"dds":"0.11864406779661019","last_synced_commit":"8844171fd936db73568333a4529a85fc1a0af912"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/leafsphp/auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafsphp","download_url":"https://codeload.github.com/leafsphp/auth/tar.gz/refs/heads/v4.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fauth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263022128,"owners_count":23401202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","leafphp","php"],"created_at":"2024-11-10T17:28:50.400Z","updated_at":"2025-07-14T15:07:29.667Z","avatar_url":"https://github.com/leafsphp.png","language":"PHP","readme":"\u003c!-- markdownlint-disable no-inline-html --\u003e\n\u003cp align=\"center\"\u003e\n  \u003cbr\u003e\u003cbr\u003e\n  \u003cimg src=\"https://leafphp.dev/logo-circle.png\" height=\"100\"/\u003e\n  \u003ch1 align=\"center\"\u003eLeaf Auth\u003c/h1\u003e\n  \u003cbr\u003e\u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/leafs/auth/v/stable)](https://packagist.org/packages/leafs/auth)\n[![Total Downloads](https://poser.pugx.org/leafs/auth/downloads)](https://packagist.org/packages/leafs/auth)\n[![License](https://poser.pugx.org/leafs/auth/license)](https://packagist.org/packages/leafs/auth)\n\nLeaf provides a lightweight but very powerful authentication system to handle all the complexities of authentication in a few lines of code. We understand that authentication is a critical part of your application, so we've made it as simple and secure as possible.\n\n## Installation\n\nYou can easily install Leaf Auth using the Leaf CLI:\n\n```bash\nleaf install auth\n```\n\nOr via composer:\n\n```sh\ncomposer require leafs/auth\n```\n\n## Connecting to a database\n\nTo do any kind of authentication, you need to connect to some kind of database which will store your users' data.\n\n```php\nauth()-\u003econnect([\n  'dbtype' =\u003e '...',\n  'charset' =\u003e '...',\n  'port' =\u003e '...',\n  'host' =\u003e '...',\n  'dbname' =\u003e '...',\n  'user' =\u003e '...',\n  'password' =\u003e '...'\n]);\n```\n\nIf you have an existing PDO connection, you can pass it to Leaf Auth:\n\n```php\n$db = new PDO('mysql:dbname=test;host=127.0.0.1', 'root', '');\n\nauth()-\u003edbConnection($db);\n\n// you can use leaf auth the same way you always have\n```\n\n## Signing a user in\n\nTo sign a user in, you can use the login() method. This method takes in an array of data you want to use to authenticate the user. This data is usually the user's email and password, but can be anything as long as the password field is present.\n\n```php\nauth()-\u003elogin([\n  'email' =\u003e 'm@example.com',\n  'password' =\u003e 'password'\n]);\n```\n\n## Signing a user up\n\nTo sign a user up is to create a new user account on your application. This is usually done by collecting the user's details and storing them in your database. You also need to validate the user's details to ensure they are correct and that they don't conflict with existing data.\n\nLeaf allows you to do all this using the register() method. This method takes in an array of data you want to use to create the user.\n\n```php\nauth()-\u003eregister([\n  'username' =\u003e 'example',\n  'email' =\u003e 'm@example.com',\n  'password' =\u003e 'password'\n]);\n```\n\n## Using Middleware\n\nLeaf Auth also provides a middleware that you can use to protect your routes. The auth middleware checks if a user is logged in and allows you to set a callback function to run if a user is not logged in.\n\n```php\nauth()-\u003emiddleware('auth.required', function () {\n  response()-\u003eredirect('/login');\n});\n```\n\nOnce you have defined a callback for the middleware, you can use it in your routes like this:\n\n```php\napp()-\u003eget('/protected', ['middleware' =\u003e 'auth.required', function () {\n  // this route is protected\n}]);\n\n// or on a route group\napp()-\u003egroup('/protected', ['middleware' =\u003e 'auth.required', function () {\n  app()-\u003eget('/route', function () {\n    // this route is protected\n  });\n}]);\n```\n\nYou can find the full documentation [here](https://leafphp.dev/docs/auth/protected-routes.html)\n\n## Stay In Touch\n\n- [Twitter](https://twitter.com/leafphp)\n- [Join the forum](https://github.com/leafsphp/leaf/discussions/37)\n- [Chat on discord](https://discord.com/invite/Pkrm9NJPE3)\n\n## Learning Leaf PHP\n\n- Leaf has a very easy to understand [documentation](https://leafphp.dev) which contains information on all operations in Leaf.\n- You can also check out our [youtube channel](https://www.youtube.com/channel/UCllE-GsYy10RkxBUK0HIffw) which has video tutorials on different topics\n- You can also learn from [codelabs](https://leafphp.dev/codelabs/) and contribute as well.\n\n## Contributing\n\nWe are glad to have you. All contributions are welcome! To get started, familiarize yourself with our [contribution guide](https://leafphp.dev/community/contributing.html) and you'll be ready to make your first pull request 🚀.\n\nTo report a security vulnerability, you can reach out to [@mychidarko](https://twitter.com/mychidarko) or [@leafphp](https://twitter.com/leafphp) on twitter. We will coordinate the fix and eventually commit the solution in this project.\n\n## Sponsoring Leaf\n\nWe are committed to keeping Leaf open-source and free, but maintaining and developing new features now requires significant time and resources. As the project has grown, so have the costs, which have been mostly covered by the team. To sustain and grow Leaf, we need your help to support full-time maintainers.\n\nYou can sponsor Leaf and any of our packages on [open collective](https://opencollective.com/leaf) or check the [contribution page](https://leafphp.dev/support/) for a list of ways to contribute.\n\nAnd to all our [existing cash/code contributors](https://leafphp.dev#sponsors), we love you all ❤️\n","funding_links":["https://opencollective.com/leaf","https://github.com/sponsors/leafsphp"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafsphp%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafsphp%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafsphp%2Fauth/lists"}