Download the PHP package sokkian/simpleauth without Composer

On this page you can find all versions of the php package sokkian/simpleauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package simpleauth

SimpleAuth

A lightweight, secure PHP library for passwordless authentication using magic links (one-time login tokens).

Project Status

⚠️ Learning/educational project - not actively maintained. Feel free to fork and adapt it for your needs.

Features

Requirements

Installation

Via Composer (Recommended)

Manual Installation

  1. Download or clone this repository
  2. Copy the src/ directory to your project:

  3. Create an autoloader file in your project root:

autoload.php:

Database Setup

Run the SQL schema to create required tables:

Or manually create tables:

Quick Start

1. Generate a Magic Link

2. Verify the Token

Complete Testing Example

Here's a minimal working example to test the installation:

test-login.php (Request magic link)

test-verify.php (Verify token)

test-logout.php (Clear session)

Testing steps:

  1. Insert a test user: INSERT INTO users (email, name) VALUES ('[email protected]', 'Test User');
  2. Open test-login.php in your browser
  3. Enter [email protected]
  4. Click the magic link displayed
  5. Verify you're logged in

API Reference

Token Class

__construct(PDO $db)

Create a new token generator.

Parameters:

generate(int $user_id, int $ttlSeconds = 900): string

Generate a new magic link token.

Parameters:

Returns: string - The generated token

Example:

cleanup(int $retentionWeeks = 4): array

Delete expired tokens and nonces.

Parameters:

Returns: array with keys:

Example:

Verifier Class

__construct(PDO $db, int $clockSkewSeconds = 120)

Create a new token verifier.

Parameters:

verify(string $token): Result

Verify a magic link token.

Parameters:

Returns: Result object

Example:

verifyFromUrl(string $url, string $paramName = 't'): Result

Extract and verify token from URL.

Parameters:

Returns: Result object

Result Class

Constants (Error Codes)

Constant Value Description
TOKEN_NOT_FOUND token_not_found Token doesn't exist in database
TOKEN_EXPIRED token_expired Token has expired
TOKEN_ALREADY_USED token_already_used Replay attack detected
MISSING_TOKEN missing_token No token provided in URL

Methods

isOk(): bool
Returns true if verification succeeded.

isFailed(): bool
Returns true if verification failed.

getReason(): ?string
Returns error code (null if success).

getData(): ?array
Returns success data array (null if failed).

getUserId(): ?int
Returns authenticated user ID (null if failed).

Internationalization

SimpleAuth includes translations for error messages in multiple languages.

Supported locales:

Customizing messages:

Messages are stored in src/locales/{locale}.php. To override messages in your application:

  1. Create directory: src/App/locales/simpleauth/
  2. Create locale file: src/App/locales/simpleauth/es_ES.php
  3. Override specific messages:

See src/locales/README.md for available message IDs.

Security Best Practices

  1. Always use HTTPS for magic link URLs
  2. Short TTL: Keep token lifetime short (5-15 minutes recommended)
  3. Rate limiting: Limit magic link requests per email/IP
  4. Email validation: Verify email ownership before generating tokens
  5. Cleanup regularly: Run cleanup() daily via cron job
  6. Monitor nonces: Alert on unusual replay attack attempts
  7. Secure sessions: Use secure session configuration after authentication

Maintenance

Cleanup Cron Job

Add to your crontab to run daily cleanup:

cleanup.php:

Troubleshooting

Problem: Token always shows as "not found"
Solution: Check that the token is being passed correctly in the URL parameter

Problem: Token shows as "expired" immediately
Solution: Check server time synchronization. Increase clockSkewSeconds if needed.

Problem: "Token already used" on first attempt
Solution: Check for duplicate requests. Ensure the token isn't being consumed multiple times.

Problem: Database errors
Solution: Verify all tables are created and foreign keys are properly set up.

Problem: Autoloader not working (manual installation)
Solution: Verify autoload.php is in the project root and the src/ path is correct.

License

MIT License - see LICENSE file for details.

Forking and Using This Project

This project is a learning exercise and not actively maintained. You are encouraged to:

If you create something interesting based on this work, feel free to share it (but not required).

Support

For questions, review the documentation above or fork the project to experiment. Limited support available at [email protected].

Changelog

1.0.0 (2025-01-15)


All versions of simpleauth with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-pdo Version *
ext-pdo_mysql Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sokkian/simpleauth contains the following files

Loading the files please wait ...