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 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 14 All time: 11,441 This week: 35Up
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
Number 3
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  
Innovation award
Innovation award
Nominee: 3x

 

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

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:14
This week:0
All time:11,441
This week:35Up