PHP Classes

How to Implement a PHP Work Verification Solution with the Package Laravel POW: Verify if a specific type of work was done

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-09-27 (7 days ago) RSS 2.0 feedNot enough user ratingsTotal: 11 This week: 11All time: 11,401 This week: 4Up
Version License PHP version Categories
laravel-pow 1.0Custom (specified...7.4User Management, Web services, PHP 7, A...
Description 

Author

This package can verify if a specific type of work was done.

It provides an API that can generate a random challenge code that can be displayed to users using Web page front-end code.

The API can also verify if the user entered a correct challenge code.

Innovation Award
PHP Programming Innovation award nominee
September 2024
Nominee
Vote
A proof of work system can verify if a certain work was done by the user or by an automated system.

It usually generates a challenge code that can be verified by checking the response of the user or the system.

This package provides a PHP proof-of-work solution implemented as an API.

A front-end application or a separate application can use this API.

The package creates a processing penalty in the form of a challenge. Real users or robots must validate the challenge passing the proof value to continue using the system.

If somebody uses a robot, that robot must match every challenge.

The processing penalty is the additional processing power necessary to match each challenge.

Since that processing power usually costs more money, using this package can discourage or even stop spammers who use robots to abuse systems managed by other people or companies.


Manuel Lemos
Picture of Mohamed Ahmed
  Performance   Level  
Name: Mohamed Ahmed <contact>
Classes: 2 packages by
Country: Egypt Egypt
Innovation award
Innovation award
Nominee: 2x

Documentation

laravel PoW "multiple frontends support"

<p align="center"> <img src="laravel-pow.svg" alt="Laravel Proof of Work" width="600"> </p>

This package implements a Proof of Work (PoW) system for Laravel applications with support for multiple front-end frameworks including Vue.js, React, and Angular.

Table of Contents

Features

  • Configurable difficulty level for Proof of Work challenges
  • Backend API for generating challenges and verifying proofs
  • Frontend components for Vue.js, React, and Angular
  • Easily integrable with existing Laravel applications

Requirements

  • PHP 7.4+
  • Laravel 8.0+
  • Node.js and NPM (for frontend components)

Installation

  1. Install the package via Composer:
composer require mohamedahmed01/laravel-pow

  1. Publish the configuration file:
php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="config"

  1. Publish the frontend component for your chosen framework:
php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="vue-component"
# Or for React:
# php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="react-component"
# Or for Angular:
# php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="angular-component"

Configuration

After publishing the configuration file, you can adjust the PoW settings in config/pow.php:

return [
    'difficulty' => env('POW_DIFFICULTY', 4),
    'front_end' => env('POW_FRONT_END', 'vue'), // Options: 'vue', 'react', 'angular'
];

You can also set these values in your .env file:

POW_DIFFICULTY=4
POW_FRONT_END=vue

Usage

Backend Usage

The package provides two main API endpoints:

  1. `GET /api/pow/challenge` - Generates a new challenge
  2. `POST /api/pow/verify` - Verifies a proof for a given challenge

You can use these endpoints in your application as needed.

Frontend Integration

Vue.js

  1. Import the component in your Vue application:
import ProofOfWork from './components/ProofOfWork.vue';

export default {
  components: {
    ProofOfWork,
  },
  // ...
}

  1. Use the component in your template:
<template>
  <div>
    <proof-of-work></proof-of-work>
  </div>
</template>

React

  1. Import the component in your React application:
import ProofOfWork from './components/ProofOfWork';

function App() {
  return (
    <div>
      <ProofOfWork />
    </div>
  );
}

Angular

  1. Import the component in your Angular module:
import { ProofOfWorkComponent } from './components/proof-of-work.component';

@NgModule({
  declarations: [ProofOfWorkComponent],
  // ...
})
export class AppModule { }

  1. Use the component in your template:
<app-proof-of-work></app-proof-of-work>

API Endpoints

GET /api/pow/challenge

Generates a new Proof of Work challenge.

Response:

{
  "challenge": "string",
  "difficulty": number
}

POST /api/pow/verify

Verifies a proof for a given challenge.

Request body:

{
  "challenge": "string",
  "proof": "string"
}

Response:

{
  "status": "success" | "failure"
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.


  Files folder image Files (23)  
File Role Description
Files folder image.github (1 directory)
Files folder imageconfig (1 file)
Files folder imagesrc (2 files, 5 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file laravel-pow.svg Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (23)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (23)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file main.yml Data Auxiliary data

  Files folder image Files (23)  /  config  
File Role Description
  Accessible without login Plain text file pow.php Aux. Configuration script

  Files folder image Files (23)  /  src  
File Role Description
Files folder imageFacades (1 file)
Files folder imageHttp (2 directories)
Files folder imageMiddleware (1 file)
Files folder imageresources (1 directory)
Files folder imageroutes (1 file)
  Plain text file LaravelPowServiceProvider.php Class Class source
  Plain text file PowManager.php Class Class source

  Files folder image Files (23)  /  src  /  Facades  
File Role Description
  Plain text file Pow.php Class Class source

  Files folder image Files (23)  /  src  /  Http  
File Role Description
Files folder imageControllers (1 file)
Files folder imageRequests (1 file)

  Files folder image Files (23)  /  src  /  Http  /  Controllers  
File Role Description
  Plain text file PowController.php Class Class source

  Files folder image Files (23)  /  src  /  Http  /  Requests  
File Role Description
  Plain text file VerifyPowRequest.php Class Class source

  Files folder image Files (23)  /  src  /  Middleware  
File Role Description
  Plain text file VerifyProofOfWork.php Class Class source

  Files folder image Files (23)  /  src  /  resources  
File Role Description
Files folder imagejs (1 directory)

  Files folder image Files (23)  /  src  /  resources  /  js  
File Role Description
Files folder imagecomponents (3 directories)

  Files folder image Files (23)  /  src  /  resources  /  js  /  components  
File Role Description
Files folder imageangular (1 file)
Files folder imagereact (1 file)
Files folder imagevue (1 file)

  Files folder image Files (23)  /  src  /  resources  /  js  /  components  /  angular  
File Role Description
  Accessible without login Plain text file proof-of-work.component.ts Data Auxiliary data

  Files folder image Files (23)  /  src  /  resources  /  js  /  components  /  react  
File Role Description
  Accessible without login Plain text file ProofOfWork.jsx Data Auxiliary data

  Files folder image Files (23)  /  src  /  resources  /  js  /  components  /  vue  
File Role Description
  Accessible without login Plain text file ProofOfWork.vue Data Auxiliary data

  Files folder image Files (23)  /  src  /  routes  
File Role Description
  Plain text file api.php Class Class source

  Files folder image Files (23)  /  tests  
File Role Description
Files folder imageFeature (2 files)
Files folder imageUnit (1 file)

  Files folder image Files (23)  /  tests  /  Feature  
File Role Description
  Plain text file PowControllerTest.php Class Class source
  Plain text file VerifyProofOfWorkMiddlewareTest.php Class Class source

  Files folder image Files (23)  /  tests  /  Unit  
File Role Description
  Plain text file PoWManagerTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:11
This week:11
All time:11,401
This week:4Up