PHPackages                             spaceshiptrooper/sarah - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. spaceshiptrooper/sarah

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

spaceshiptrooper/sarah
======================

Sarah is a 2 Factor Authentication library built in PHP.

v0.1(8y ago)088LGPL-2.1-onlyPHPPHP &gt;=5.4.0

Since Feb 8Pushed 8y agoCompare

[ Source](https://github.com/spaceshiptrooper/Sarah)[ Packagist](https://packagist.org/packages/spaceshiptrooper/sarah)[ RSS](/packages/spaceshiptrooper-sarah/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Sarah
=====

[](#sarah)

Sarah is a 2 Factor Authentication library built in `PHP`.

---

### Requirements

[](#requirements)

---

- PHP 5.4+
- `MySQL` database
- `composer`

---

### Prerequisites

[](#prerequisites)

---

#### Install Composer

[](#install-composer)

---

##### NOTE

[](#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 &amp; Mac

[](#linux--mac)

---

1. The first thing we need is `composer` so we shall download it from this website.
2. Next step is to use the codes on that page. If you are unfamiliar with `Linux` and `Mac`, you have to open up your terminal. Once in the terminal, type the lines in order; 1 by 1.
3. We will copy the `composer-setup.php` file from the official `composer` website by using the below code.

```
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

```

4. We check to make sure that there was no error in downloading the `composer-setup.php` file from the `composer` website using the below code.

```
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

```

5. We set up our `composer-setup.php` file. This will download a new file called `composer.phar` which is the file we need to run the actual `composer` commands using the below code.

```
php composer-setup.php

```

6. We then delete the `composer-setup.php` file since we don't need it anymore in the below code.

```
php -r "unlink('composer-setup.php');"

```

7. Here, we are moving the `composer.phar` file to global use. So we can do commands such as `composer require composer.json` instead of `/home/user/Downloads/composer.phar require composer.json`.

```
sudo mv composer.phar /usr/local/bin/composer

```

---

##### Windows

[](#windows)

---

`Composer` on `Windows` is actually a little simpler. You just need to download the `Composer-Setup.exe` file located on . 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.

1. Open up a file file explorer.
2. Right click on This PC.
3. From the context menu, select the option `Properties`.
4. 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.
5. On the left sidebar, click on the option `Advanced system settings`. This will bring up another new window.
6. From this window, click on the `Advanced` tab.
7. While in the `Advanced` tab, look for the `Edit` button.
8. Click on it, it'll allow you to edit your paths.
9. Add the exact path to your `composer.phar` file 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

[](#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&amp;paste the below code into your new database. A `GUI` such as `phpMyAdmin` should suffice.

```
CREATE TABLE `two_factor_authentication` (
  `id` int(11) NOT NULL,
  `user_id` int(11) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `authkey` text DEFAULT NULL,
  `hash` text DEFAULT NULL,
  `ip` varchar(100) DEFAULT NULL,
  `agent` varchar(255) DEFAULT NULL,
  `timestamp` int(11) DEFAULT NULL,
  `status` int(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `two_factor_authentication`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `two_factor_authentication`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

```

---

### Installing `Sarah`

[](#installing-sarah)

---

In the terminal (`Linux`, `Windows`, and `Mac`), type in

```
composer require spaceshiptrooper/sarah

```

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](https://github.com/spaceshiptrooper/Sarah/issues).

---

Once you have finally downloaded `Sarah`'s files and `PHPMailer`, your directory should look something similar to this.

```
vendor
  |___
      |----- composer
      |
      |----- ircmaxell
      |
      |----- phpmailer
      |
      |----- spaceshiptrooper
      |
      |----- autoload.php

```

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`

[](#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.

```
