{"id":22669049,"url":"https://github.com/mariojgt/castle","last_synced_at":"2026-02-04T02:05:52.638Z","repository":{"id":62524045,"uuid":"424765613","full_name":"mariojgt/castle","owner":"mariojgt","description":"This laravel package is a very simple way to implement 2 steps verification in your current application with almost zero setup.","archived":false,"fork":false,"pushed_at":"2025-01-08T15:05:04.000Z","size":6449,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T18:01:42.886Z","etag":null,"topics":["2fa","2factor","2steps","easy-to-use","laravel","php","safety","two-factor-authentication","two-steps-authentication","verification"],"latest_commit_sha":null,"homepage":"","language":"CSS","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/mariojgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-11-04T23:09:32.000Z","updated_at":"2025-01-08T15:04:42.000Z","dependencies_parsed_at":"2024-08-03T15:59:46.885Z","dependency_job_id":"cf6bacf6-8b3c-497c-8381-481ecb9f9fd8","html_url":"https://github.com/mariojgt/castle","commit_stats":{"total_commits":80,"total_committers":2,"mean_commits":40.0,"dds":"0.050000000000000044","last_synced_commit":"495f630c7e2148a675654d57b8ea924770b3577c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariojgt%2Fcastle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariojgt%2Fcastle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariojgt%2Fcastle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariojgt%2Fcastle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mariojgt","download_url":"https://codeload.github.com/mariojgt/castle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557844,"owners_count":21124168,"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":["2fa","2factor","2steps","easy-to-use","laravel","php","safety","two-factor-authentication","two-steps-authentication","verification"],"created_at":"2024-12-09T15:18:13.155Z","updated_at":"2026-02-04T02:05:52.606Z","avatar_url":"https://github.com/mariojgt.png","language":"CSS","readme":"\n![Logo](https://raw.githubusercontent.com/mariojgt/castle/main/Publish/Art/logo.png)\n\n\n# Castle\n\nThis Laravel package help you quickly add 2fa authentication in you existing application, simular to google authentication.\n\n\n## Features\n\n- Demo with the example application flow you need.\n- 2 steps autentication.\n- middleware protection.\n\n\n## Badges\n\n[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)\n[![version](https://img.shields.io/packagist/v/mariojgt/castle?style=for-the-badge)](http://www.gnu.org/licenses/agpl-3.0)\n\n\n## Installation\n\nInstall my-project with composer\n\n```bash\n  composer require mariojgt/castle\n  php artisan install::castle\n```\n    \n## Usage/Examples\n\n1: You need to assign the trait to you user model table in order to use the 2steps verification and have access to the backup codes.\n\n```php\nuse Mariojgt\\Castle\\Trait\\Castle;\n\nclass User extends Authenticatable\n{\n    use HasApiTokens, HasFactory, Notifiable, Castle;\n\n    /**\n     * The attributes that are mass assignable.\n     *\n     * @var string[]\n     */\n    protected $fillable = [\n        'name',\n        'email',\n        'password',\n    ];\n```\nthis will insure you have access to the backup codes\n\n2: In order to sync the user you need to first generate the authenticator secret using the helper normally when you register or with a controller method to sync the authenticator\n```php\nuse Mariojgt\\Castle\\Helpers\\AuthenticatorHandle;\n\nclass myController\n{\n    public register () {\n\t    // Start the class that handle most of the logic\n\t    $handle = new AuthenticatorHandle();\n\t    // Generate the code\n\t\t$codeInfo =\t    $handle-\u003egenerateCode($userEmail);\n\t\t// Sync that code with the user using the trait\n\t\tAuth()-\u003euser()-\u003esyncAuthenticator($codeInfo['secret']);\n    }\n```\n\n3: At this point the authenticator is enabled against that user, now you need to protect the middleware here is a example\n\n```php\n// Auth Route Example\nRoute::group([\n    'middleware' =\u003e ['web', '2fa'], // note you can use (2fa:admin) for admin guard or leave empty for web as default\n], function () {\n    // Example page required to be login\n    Route::get('/castle-try', [HomeContoller::class, 'protected'])-\u003ename('castle.try');\n});\n```\n4: Display the user codes, normaly you only display the backup codes once you can use the following example\n\n```php\nAuth()-\u003euser()-\u003egetCodes; // this will return the backup codes for that user\n```\n5: using backup codes see the example\n\n```php\nuse Mariojgt\\Castle\\Helpers\\AuthenticatorHandle;\n\nmyclass {\n\n\tpublic myFunction () {\n\t\t // Start the class that handle most of the logic\n\t\t$handle = new AuthenticatorHandle();\n\t\t// the encryption is using the normal laravel encrypt fuction // example encrypt('user_secret')\n\t\t$handle-\u003euseBackupCode($codeYouType, $encryptauthenticatorSecret); // The second parameter is not required\n\t}\n\n}\n```\n## Tech Stack\n\n**Client:** TailwindCSS, vuejs, blade\n\n**Server:** 2fa, Laravel\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariojgt%2Fcastle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariojgt%2Fcastle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariojgt%2Fcastle/lists"}