Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some small changes over readme file #364

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,18 +34,53 @@ 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.

**Match an OTP:**

```php
$valid = Otp::match($otp, $unique_secret);
$valid = Otp::match($otp, $uniqueSecret);
// Returns - boolean
```

Expand Down Expand Up @@ -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))
Binary file added resources/otp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/otp.psd
Binary file not shown.
1 change: 0 additions & 1 deletion resources/otp.svg

This file was deleted.