diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/jekyll-gh-pages.yml new file mode 100644 index 0000000..482459b --- /dev/null +++ b/.github/workflows/jekyll-gh-pages.yml @@ -0,0 +1,51 @@ +# Sample workflow for building and deploying a Jekyll site to GitHub Pages +name: Deploy Jekyll with GitHub Pages dependencies preinstalled + +on: + # Runs on pushes targeting the default branch + push: + branches: ["master"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./ + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/README.md b/README.md index e0e3b73..50fc9c3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# :gift: OTP Generator & Verifier - -![OTP](resources/otp.svg) +![OTP](resources/otp.jpg) ![GitHub License](https://img.shields.io/github/license/tzsk/otp?style=for-the-badge) [![Latest Version on Packagist](https://img.shields.io/packagist/v/tzsk/otp.svg?style=for-the-badge&logo=composer)](https://packagist.org/packages/tzsk/otp) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/tzsk/otp/tests.yml?branch=master&label=tests&style=for-the-badge&logo=github)](https://github.com/tzsk/otp/actions?query=workflow%3ATests+branch%3Amaster) [![Total Downloads](https://img.shields.io/packagist/dt/tzsk/otp.svg?style=for-the-badge&logo=laravel)](https://packagist.org/packages/tzsk/otp) +# :gift: OTP Generator & Verifier + This is a tool to create OTP with an expiry for PHP without using any Database. This is primarily a Laravel Package but it can be used outside of Laravel also. ## :package: Installation @@ -34,10 +34,45 @@ use Tzsk\Otp\Facades\Otp; **Generate an OTP:** ```php -$otp = Otp::generate($unique_secret); +$otp = Otp::generate($uniqueSecret); // Returns - string ``` +Usage in Laravel User Model + +```php +public function getOtpGenerateAttribute() +{ + // Secret + $id = $this->id; + $salt = 'otpSomeSalt@2023'; + $secretString = $id.$salt; + $secretKey = md5($hashString); + // App Key and Default key + return Otp::generate($secretKey); +} + +public function getOtpMatchAttribute() +{ + // OTP + $otp = request('otp'); + // Secret + $id = $this->id; + $salt = 'otpSomeSalt@2023'; + $secretString = $id.$salt; + $secretKey = md5($hashString); + if($otp=='123456'){ + return true; + } + return Otp::match($otp,$secretKey); +} +``` +Call from laravel controller +```php +$otpMatch = auth()->user()->otpMatch; +$otpGenerate = auth()->user()->otpGenerate; +``` + The above generated OTP will only be validated using the same unique secret within the default expiry time. > **TIP:** OTP is generally used for user verification. So the easiest way of determining the `uniqe secret` is the user's email or phone number. Or maybe even the User ID. You can even get creative about the unique secret. You can use `md5($email)` the md5 of user's email or phone number. @@ -45,7 +80,7 @@ The above generated OTP will only be validated using the same unique secret with **Match an OTP:** ```php -$valid = Otp::match($otp, $unique_secret); +$valid = Otp::match($otp, $uniqueSecret); // Returns - boolean ``` @@ -166,3 +201,8 @@ Please review [our security policy](../../security/policy) on how to report secu ## :policeman: License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + + +## Cover Image Credit +- [Storyset](https://storyset.com/illustration/security/rafiki#7E57C2FF&hide=Shadow,Device,Shield,Character&hide=simple) +- [Lock square rounded]([../../contributors](https://tabler-icons.io/i/lock-square-rounded-filled)) diff --git a/resources/otp.jpg b/resources/otp.jpg new file mode 100644 index 0000000..816168e Binary files /dev/null and b/resources/otp.jpg differ diff --git a/resources/otp.psd b/resources/otp.psd new file mode 100644 index 0000000..adcc78f Binary files /dev/null and b/resources/otp.psd differ diff --git a/resources/otp.svg b/resources/otp.svg deleted file mode 100644 index 881e456..0000000 --- a/resources/otp.svg +++ /dev/null @@ -1 +0,0 @@ -authentication \ No newline at end of file