Skip to content

Commit

Permalink
Renamed package from PIN to TOTP
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoraddatz committed Apr 19, 2024
1 parent fe9350a commit 1f2b263
Show file tree
Hide file tree
Showing 44 changed files with 619 additions and 613 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/empuxa/laravel-pin-login/discussions/new?category=q-a
url: https://github.com/empuxa/laravel-totp-login/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/empuxa/laravel-pin-login/discussions/new?category=ideas
url: https://github.com/empuxa/laravel-totp-login/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/empuxa/laravel-pin-login/security/policy
url: https://github.com/empuxa/laravel-totp-login/security/policy
about: Learn how to notify us for sensitive bugs
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Laravel PIN Login
# Laravel TOTP Login

[![Latest Version on Packagist](https://img.shields.io/packagist/v/empuxa/laravel-pin-login.svg?style=flat-square)](https://packagist.org/packages/empuxa/laravel-pin-login)
[![Tests](https://img.shields.io/github/actions/workflow/status/empuxa/laravel-pin-login/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/empuxa/laravel-pin-login/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/empuxa/laravel-pin-login.svg?style=flat-square)](https://packagist.org/packages/empuxa/laravel-pin-login)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/empuxa/laravel-totp-login.svg?style=flat-square)](https://packagist.org/packages/empuxa/laravel-totp-login)
[![Tests](https://img.shields.io/github/actions/workflow/status/empuxa/laravel-totp-login/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/empuxa/laravel-totp-login/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/empuxa/laravel-totp-login.svg?style=flat-square)](https://packagist.org/packages/empuxa/laravel-totp-login)

![Banner](https://banners.beyondco.de/Laravel%20PIN%20Login.png?theme=light&packageManager=composer+require&packageName=empuxa%2Fpin-login&pattern=architect&style=style_1&description=Goodbye+passwords%21&md=1&showWatermark=0&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg)
![Banner](https://banners.beyondco.de/Laravel%20TOTP%20Login.png?theme=light&packageManager=composer+require&packageName=empuxa%2Ftotp-login&pattern=architect&style=style_1&description=Goodbye+passwords%21&md=1&showWatermark=0&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg)

Say goodbye to passwords and sign in via PIN instead!
Laravel PIN Login is a convenient package that allows you to easily add a PIN login feature to your Laravel application.
Say goodbye to passwords and sign in via a time-based one-time password instead!
Laravel TOTP Login is a convenient package that allows you to easily add a TOTP login feature to your Laravel application.

## Why Choose Laravel PIN Login?
You might wonder why you should opt for a PIN login instead of a magic link solution. Well, this package is designed to complement the existing login methods in your application. It provides an alternative sign-in option for users who haven't set a password yet or don't have an email address. For instance, users who signed up with only a phone number can still enjoy the benefits of secure login through a PIN.
## Why Choose Laravel TOTP Login?
You might wonder why you should opt for a TOTP login instead of a magic link solution.
Well, this package is designed to complement the existing login methods in your application.
It provides an alternative sign-in option for users who haven't set a password yet or don't have an email address.
For instance, users who signed up with only a phone number can still enjoy the benefits of secure login through a TOTP.

## Features
- Simplified sign-in process using a PIN
- Simplified sign-in process using a TOTP
- Compatibility with existing login methods
- Support for users without passwords or email addresses

Expand All @@ -31,13 +34,13 @@ Also, you need to have a notifiable user model.
Install the package via composer:

```bash
composer require empuxa/laravel-pin-login
composer require empuxa/laravel-totp-login
```

Copy the vendor files and adjust the config file `config/pin-login.php` to your needs:
Copy the vendor files and adjust the config file `config/totp-login.php` to your needs:

```bash
php artisan vendor:publish --provider="Empuxa\PinLogin\PinLoginServiceProvider"
php artisan vendor:publish --provider="Empuxa\TotpLogin\TotpLoginServiceProvider"
```

Run the migrations:
Expand All @@ -47,37 +50,38 @@ php artisan migrate
```

That's it!
You're ready to start using the PIN login feature in your Laravel application.
You're ready to start using the TOTP login feature in your Laravel application.

## Usage

The sign-in process for this repository involves three steps:
1. Enter the user's email address, phone number, or any other specified identifier, and request a PIN.
2. If the entered information is valid, a PIN will be sent to the user. You may need to customize the notification channel based on the user model you are using.
3. Enter the received PIN to log in the user.
1. Enter the user's email address, phone number, or any other specified identifier, and request a TOTP.
2. If the entered information is valid, a TOTP will be sent to the user. You may need to customize the notification channel based on the user model you are using.
3. Enter the received TOTP to log in the user.

### Customizing the Views

While the initial steps are relatively straightforward, it's now necessary to customize the views.
These views have been designed to be as simple as possible (some might even consider them "ugly") and can be located in the `resources/views/vendor/pin-login` directory.
These views have been designed to be as simple as possible (some might even consider them "ugly") and can be located in the `resources/views/vendor/totp-login` directory.

*Why are they not visually appealing?*
Different applications adopt various layouts and frameworks.
Since you have the most knowledge about your application, you can change the views to suit your specific requirements.

### Modifying the Notification
Within the copied views, you will come across a notification that's sent to the user.
Within the copied views, you will come across a notification sent to the user.
You may want to make adjustments to this notification to align it with your preferences and needs.

#### Different Notification Channels
If you plan on utilizing SMS or similar as your preferred notification channel, you have the option to create a custom notification class.
The PIN and the user's IP address will be passed to the constructor of this class. Finally, replace the default notification class within the `config/pin-login.php` file with your custom notification.
If you plan on using SMS or similar as your preferred notification channel, you can create a custom notification class.
The TOTP and the user's IP address will be passed to the constructor of this class.
Finally, replace the default notification class within the `config/totp-login.php` file with your custom notification.

### Custom User Model Scope
To apply a scope to your user model, add the following method to your model:

```php
public static function pinLoginScope(): Builder
public static function totpLoginScope(): Builder
{
return self::yourGlobalScope();
}
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "empuxa/laravel-pin-login",
"name": "empuxa/laravel-totp-login",
"description": "Say goodbye to passwords and sign in via PIN instead.",
"keywords": [
"empuxa",
"pin-login",
"totp-login",
"passwordless"
],
"homepage": "https://github.com/empuxa/laravel-pin-login",
"homepage": "https://github.com/empuxa/laravel-totp-login",
"license": "MIT",
"authors": [
{
Expand All @@ -33,12 +33,12 @@
},
"autoload": {
"psr-4": {
"Empuxa\\PinLogin\\": "src"
"Empuxa\\TotpLogin\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Empuxa\\PinLogin\\Tests\\": "tests"
"Empuxa\\TotpLogin\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -55,7 +55,7 @@
"extra": {
"laravel": {
"providers": [
"Empuxa\\PinLogin\\PinLoginServiceProvider"
"Empuxa\\TotpLogin\\TotpLoginServiceProvider"
]
}
},
Expand Down
36 changes: 18 additions & 18 deletions config/pin-login.php → config/totp-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@

/**
* The notification to send to the user.
* Default: \Empuxa\PinLogin\Notifications\LoginPin::class
* Default: \Empuxa\TotpLogin\Notifications\LoginCode::class
*/
'notification' => \Empuxa\PinLogin\Notifications\LoginPin::class,
'notification' => \Empuxa\TotpLogin\Notifications\LoginCode::class,

'columns' => [
/**
* The main identifier of the user model.
* We will use this column to authenticate the user and to send the PIN to.
* Default: 'email'
*/
'identifier' => 'email',
'identifier' => 'email',

/**
* The column where the PIN is stored.
* Default: 'login_pin'
* Default: 'login_totp_code'
*/
'pin' => 'login_pin',
'code' => 'login_totp_code',

/**
* The column where we store the information, how long the PIN is valid.
* Default: 'login_pin_valid_until'
* Default: 'login_totp_code_valid_until'
*/
'pin_valid_until' => 'login_pin_valid_until',
'code_valid_until' => 'login_totp_code_valid_until',
],

'route' => [
Expand Down Expand Up @@ -71,7 +71,7 @@
'enable_throttling' => true,
],

'pin' => [
'code' => [
/**
* The length of the PIN.
* Keep in mind that longer PINs might break the layout.
Expand All @@ -81,7 +81,7 @@

/**
* The time in seconds after which the PIN expires.
* This is the information being stored in the `login_pin_valid_until` column.
* This is the information being stored in the `login_totp_code_valid_until` column.
* Default: 600
*/
'expires_in' => 600,
Expand Down Expand Up @@ -111,10 +111,10 @@
/**
* Enable the "superpin" feature.
* When enabled, any user can also sign in with the PIN of your choice on non-production environments.
* Set the environment variable `PIN_LOGIN_SUPERPIN` to the PIN you want to use.
* Default: env('PIN_LOGIN_SUPERPIN', false)
* Set the environment variable `TOTP_LOGIN_SUPERPIN` to the PIN you want to use.
* Default: env('TOTP_LOGIN_SUPERPIN', false)
*/
'superpin' => env('PIN_LOGIN_SUPERPIN', false),
'superpin' => env('TOTP_LOGIN_SUPERPIN', false),

/**
* The redirect path after a successful login.
Expand All @@ -124,21 +124,21 @@

'events' => [
/**
* This event is fired when a user submits a PIN.
* Default: \Empuxa\PinLogin\Events\PinRequested::class
* This event is fired when a user submits a TOTP.
* Default: \Empuxa\TotpLogin\Events\PinRequested::class
*/
'login_request_via_pin' => \Empuxa\PinLogin\Events\LoginRequestViaPin::class,
'login_request_via_totp' => \Empuxa\TotpLogin\Events\LoginRequestViaTotp::class,

/**
* This event is fired when a user was successfully logged in.
* Default: \Empuxa\PinLogin\Events\LoggedInViaPin::class
* Default: \Empuxa\TotpLogin\Events\LoggedInViaTotp::class
*/
'logged_in_via_pin' => \Empuxa\PinLogin\Events\LoggedInViaPin::class,
'logged_in_via_totp' => \Empuxa\TotpLogin\Events\LoggedInViaTotp::class,

/**
* This event is fired when a user was successfully logged in.
* Default: \Illuminate\Auth\Events\Lockout::class
*/
'lockout' => \Illuminate\Auth\Events\Lockout::class,
'lockout' => \Illuminate\Auth\Events\Lockout::class,
],
];

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table(app(config('totp-login.model'))->getTable(), static function (Blueprint $table): void {
$table->string(config('totp-login.columns.code'))->nullable();
$table->timestamp(config('totp-login.columns.code_valid_until'))->nullable();
});
}

public function down(): void
{
Schema::table(app(config('totp-login.model'))->getTable(), static function (Blueprint $table): void {
$table->dropColumn([
config('totp-login.columns.code'),
config('totp-login.columns.code_valid_until'),
]);
});
}
};
26 changes: 0 additions & 26 deletions database/migrations/add_pin_columns_to_users_table.php.stub

This file was deleted.

26 changes: 26 additions & 0 deletions database/migrations/add_totp_columns_to_users_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table(app(config('totp-login.model'))->getTable(), static function (Blueprint $table): void {
$table->string(config('totp-login.columns.code'))->nullable();
$table->timestamp(config('totp-login.columns.code_valid_until'))->nullable();
});
}

public function down(): void
{
Schema::table(app(config('totp-login.model'))->getTable(), static function (Blueprint $table): void {
$table->dropColumn([
config('totp-login.columns.code'),
config('totp-login.columns.code_valid_until'),
]);
});
}
};
6 changes: 3 additions & 3 deletions resources/lang/de/controller.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

return [
'handle_pin_request' => [
'handle_code_request' => [
'success' => 'Login erfolgreich.',
'error' => [
'rate_limit' => 'Zu viele falsche Anfragen. Ihre Account wurde für :seconds Sekunden geblockt.',
'expired' => 'Der eingegebene PIN ist nicht mehr gültig. Wir haben Ihnen einen neuen PIN per E-Mail geschickt.',
'wrong_pin' => 'Der PIN ist ungültig. Sie haben noch :attempts_left Versuche bis wir Ihren Account temporär blockieren.',
'expired' => 'Der eingegebene Code ist nicht mehr gültig. Wir haben Ihnen einen neuen Code per E-Mail geschickt.',
'wrong_totp' => 'Der Code ist ungültig. Sie haben noch :attempts_left Versuche bis wir Ihren Account temporär blockieren.',
],
],
];
12 changes: 6 additions & 6 deletions resources/lang/de/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

return [
'mail' => [
'subject' => 'Your login PIN for :app',
'greeting' => 'Hello :name,',
'line-1' => 'There was a login request from :ip. Here is your PIN, which is valid until :valid_until:',
'line-2' => "If it wasn't you: no reason to panic. You can find more information about our login process here: https://google.com",
'line-3' => "Thank you for using our services. If you have any questions, please contact us. We're happy to help!",
'cta' => 'Sign in now',
'subject' => 'Ihr Anmeldecode für :app',
'greeting' => 'Hallo :name,',
'line-1' => 'Es gab eine Anmeldeanforderung von :ip. Hier ist Ihr Code, gültig bis :valid_until:',
'line-2' => 'Falls Sie dies nicht waren: Kein Grund zur Panik. Weitere Informationen zu unserem Anmeldeverfahren finden Sie hier: https://google.com',
'line-3' => 'Vielen Dank, dass Sie unsere Dienste nutzen. Bei Fragen stehen wir Ihnen gerne zur Verfügung!',
'cta' => 'Jetzt anmelden',
],
];
Loading

0 comments on commit 1f2b263

Please sign in to comment.