PHPackages                             prince-rai/core-php-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. prince-rai/core-php-auth

ActiveLibrary

prince-rai/core-php-auth
========================

A lightweight authentication package for Core PHP with JWT

v1.0.1(1y ago)02MITPHPPHP &gt;=7.4

Since Apr 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/laravel-princerai/prince-rai-core-php-auth)[ Packagist](https://packagist.org/packages/prince-rai/core-php-auth)[ RSS](/packages/prince-rai-core-php-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Core PHP Auth
=============

[](#core-php-auth)

**Core PHP Authentication** package provides essential functionalities for user authentication, including registration, login, JWT token generation, and token verification. It is designed to be simple, flexible, and lightweight for PHP developers.

Features
--------

[](#features)

- **User Registration**: Hash and store user passwords.
- **User Login**: Authenticate users using email and password, generate JWT token.
- **JWT Token Generation**: Generate JWT token for authenticated users.
- **JWT Token Verification**: Verify JWT tokens for access control to protected routes.
- **Configurable**: Allows you to set a custom JWT secret key for encryption.

Requirements
------------

[](#requirements)

- PHP 7.4+ (Recommended PHP 8.0+)
- MySQL or compatible relational database (like MariaDB)
- Composer (for package management)

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

To install the package via Composer, run the following command in your terminal or command prompt from your project root:

```
composer require prince-rai/core-php-auth
```

This will automatically download and install the package along with its dependencies.

### 2. Configure the Database

[](#2-configure-the-database)

You will need to create a database and a **`users`** table to store user information. Here’s the SQL query to create the necessary table:

```
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,      -- User ID (Primary Key)
    name VARCHAR(255) NOT NULL,             -- User Name
    email VARCHAR(255) NOT NULL UNIQUE,     -- User Email (must be unique)
    password VARCHAR(255) NOT NULL          -- User Password (hashed)
);
```

This table stores the user's **ID**, **Name**, **Email** (unique), and **Password** (hashed).

### 3. Configuration File

[](#3-configuration-file)

The JWT secret key is required for signing and verifying JWT tokens. To set this, create a **`config/config.php`** file in your project and configure your secret key (by default we're generating a new one during registeration , so if you wish to modify it you are good to go):

```
