Skip to content

studio24/staging-site-password

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Staging site password

A simple tool to password restrict a staging environment.

What does it do?

When creating or updating a website it's good practise to publish changes to a staging environment to review before going live.

This package helps secure staging websites behind a simple, accessible login page. This is easier to use than basic authentication and remembers your login in a cookie, so you don't have to keep entering your password.

Screenshot of the staging site password login page

Requirements

Installation

Install via Composer:

composer require studio24/staging-site-passsword:^1.0

Usage

Create a password hash

Your staging site password needs to be stored as secure hash. You can generate this via password_hash or by using the provided command line script.

php vendor/bin/password-hash.php

Store the password hash

TODO

Store the password hash in an environment variable or PHP constant. The example below is for the password "test123"

Environment variable:

putenv('STAGING_SITE_PASSWORD=$2y$10$pvDrmW9GW0bLVDMtLwLnn.mFof5eQQwlozZ5kYK7xijQRVAWUw0FK');

PHP constant:

define('STAGING_SITE_PASSWORD', '$2y$10$pvDrmW9GW0bLVDMtLwLnn.mFof5eQQwlozZ5kYK7xijQRVAWUw0FK');

Or in PHP:

$controller->auth->setPasswordHash($hash); 

Integrate with your website

WordPress

TODO

Laravel

PHP websites

Enable the staging site login page via:

$controller = new \Studio24\StagingSitePassword\Controller();
if ($controller->isStaging()) {
    $controller->authenticate();
}

How to customise the login page

If you want to customise any options, you can do so via the controller object. Make sure you add your code before $controller->authenticate() is run. For example:

$controller = new \Studio24\StagingSitePassword\Controller();
$controller->loginPage->setPlaceholder('title', 'Login to My Website');
if ($controller->isStaging()) {
    $controller->authenticate();
}

Text

You can customise any text on the login page via $controller->loginPage->setPlaceholder($name, $value).

Customise the title:

$controller->loginPage->setPlaceholder('title', 'Login to My Website');

Customise the footer text (you can include HTML):

$controller->loginPage->setPlaceholder('footer', 'Get support from <a href="mailto:[email protected]">Studio 24</a>');

The full list of placeholders:

Placeholder Default content
title Login to staging website
footer
password_field_label Password
submit_field_label Login
title_prefix_on_error Error:
error_message_title There is a problem
error_message The password is incorrect
show Show
hide Hide
show_password Show password
hide_password Hide password

Cookie lifetime

By default, the login cookie is set to expire after 1 day. You can customise this via:

$controller->auth->setCookieLifetime(3600); 

This sets the cookie lifetime in seconds.

You can also set this in days:

$controller->auth->setCookieLifetimeInDays(7); 

You can also change the cookie name (default is staging_site_remember_login):

$controller->auth->setCookieName('remember_me'); 

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published