Download the PHP package spaceshiptrooper/sarah without Composer
On this page you can find all versions of the php package spaceshiptrooper/sarah. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spaceshiptrooper/sarah
More information about spaceshiptrooper/sarah
Files in spaceshiptrooper/sarah
Package sarah
Short Description Sarah is a 2 Factor Authentication library built in PHP.
License LGPL-2.1-only
Informations about the package sarah
Sarah
Sarah is a 2 Factor Authentication library built in PHP.
Requirements
- PHP 5.4+
MySQLdatabasecomposer
Prerequisites
Install Composer
NOTE
Before we can start using Sarah, we must install composer in order to grab Sarah's dependencies. Sarah is dependent on the PHPMailer library to send emails. If you already have an up-to-date version of PHPMailer, you can skip this part. However, you will have to move the PHPMailer into the vendor directory if you have not already done that. Sarah looks for PHPMailer in the vendor directory.
Linux & Mac
- The first thing we need is
composerso we shall download it from this website. https://getcomposer.org/download/ -
Next step is to use the codes on that page. If you are unfamiliar with
LinuxandMac, you have to open up your terminal. Once in the terminal, type the lines in order; 1 by 1. -
We will copy the
composer-setup.phpfile from the officialcomposerwebsite by using the below code. -
We check to make sure that there was no error in downloading the
composer-setup.phpfile from thecomposerwebsite using the below code. -
We set up our
composer-setup.phpfile. This will download a new file calledcomposer.pharwhich is the file we need to run the actualcomposercommands using the below code. -
We then delete the
composer-setup.phpfile since we don't need it anymore in the below code. - Here, we are moving the
composer.pharfile to global use. So we can do commands such ascomposer require composer.jsoninstead of/home/user/Downloads/composer.phar require composer.json.
Windows
Composer on Windows is actually a little simpler. You just need to download the Composer-Setup.exe file located on https://getcomposer.org/doc/00-intro.md#installation-windows. Once you open up that application, you start the installation process. You will have to locate your php.exe file and composer will start installing. If you want to make a global use like the Linux and Mac one, you'll have to add the location of the composer.phar file in your PATH variables.
To do this follow these steps.
- Open up a file file explorer.
- Right click on This PC.
- From the context menu, select the option
Properties. - This should bring up a new window that's in the settings which basically lists your Window's version and what the specs are to it and what not.
- On the left sidebar, click on the option
Advanced system settings. This will bring up another new window. - From this window, click on the
Advancedtab. - While in the
Advancedtab, look for theEditbutton. - Click on it, it'll allow you to edit your paths.
- Add the exact path to your
composer.pharfile into the text box and ending it with a;. This semicolon will separate each individual value as an actual path so be cautious what you use the semicolon for. More paths means more semicolons.
Importing the database
Sarah uses PDO as her database API. Assuming you understand what that means, we are using the MySQL server. So if you have access to your MySQL databases, create a database and copy&paste the below code into your new database. A GUI such as phpMyAdmin should suffice.
Installing Sarah
In the terminal (Linux, Windows, and Mac), type in
This will create a composer.json file in the current directory you are in and then download Sarah's files along with PHPMailer. This process might take a few minutes because we are requiring both Sarah's files and PHPMailer so there's a lot of files that are needed. Just wait and be patient. If you receive an error please submit it here.
Once you have finally downloaded Sarah's files and PHPMailer, your directory should look something similar to this.
The composer directory and the cache strings within the composer files are generated from the composer command. ircmaxell is a requirement and downloaded from https://github.com/ircmaxell/password_compat. This is for backwards compatibility and support for users who are using PHP 5.4 and lower. Lowest support for this library is 5.3.7 due to some buggy issues with lower versions than that. If you are using PHP 5.5 and higher, then you don't have to worry about this library since PHP 5.5 has this function built-in. So this library will be ignored. The spaceshiptrooper directory is where Sarah lies. The autoload.php file is also generated from composer. However, some respositories require the autoload.php file while some don't. ircmaxell, phpmailer, and Sarah all don't require autoload.php, but it comes with the composer command anyways. So that's fine.
How to use Sarah
The next step is to include Sarah's bootstrap.php file in your application. You should only call Sarah's sendMail() method during a POST request. Sending it via a GET request can be redundant and unnecessary.
The below is to instantiate Sarah's class.
A little side note
By default, the cost for password_hash is 10. However, you can specify as much cost as you want. The more the cost, the more secure the password is, however, the more resource it takes. The less the cost, the less secure the password is. And the less resource it takes. It's really up to you to find the balance between the 2.
You can use the below code in your POST request.
To verify if the user has already been authenticated, a $_SESSION has been set upon authentication. So we can just check to see if that $_SESSION cookie has been set, if it has, the user has authenticated successfully.
This is where you can basically allow the user to login either through your own $_SESSION cookie or through something else.
What is SMTP?
Simple Mail Transfer Protocol (SMTP) is the next thing to sending emails. The default mail() function that PHP has should not be relied on. This function can or cannot work at random times. There is no 100% guarantees when using the mail() function. What does this mean? It means that PHP's mail() function may or may not send any emails at all to its specified destination. That is why Sarah's choice of sending emails is through an SMTP library called PHPMailer.
What is the difference in usage between SMTP libraries and the mail() function?
There is a huge difference. SMTP requires multiple information. You need to provide the SMTP host, the SMTP username (also considered as SMTP email), the SMTP password, the SMTP port, and the SMTP protocol type (tls or ssl). Whereas, the mail() function only requires the receiver's email address, a subject line, and a message body.
Now. You may ask, "Why can't we just use the mail() function since it's so easy and takes less time to comprehend?" And the simple answer, "You just can't rely on it. There is no guarantee that it will even send any emails to your desired destination."
Even if it sends emails about 7/10 of the time, here's a topic I created since I saw this in my email subscription not too long ago. This relates to the use of the mail() function.
SMTP information isn't really too hard to come across honestly. You can actually use your Gmail, Hotmail, or Ymail for SMTP. Here are a few articles on how to setup SMTP using your Gmail, Hotmail, and Ymail. You can apply these same steps to Sarah.
https://wpsitecare.com/gmail-smtp-settings/ <-- Gmail
https://lifewire.com/what-are-windows-live-hotmail-smtp-settings-1170861 <-- Hotmail
https://help.yahoo.com/kb/SLN4724.html <-- Ymail
Once you are done setting up Sarah, give it a twirl. Hopefully you didn't break it! Enjoy.
All versions of sarah with dependencies
phpmailer/phpmailer Version ~6.0
ircmaxell/password-compat Version ^1.0