1. Go to this page and download the library: Download rougin/authsum library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php
// index.php
use Rougin\Authsum\Source\PdoSource;
// ...
// Create a PDO instance... --------------
$dsn = 'mysql:host=localhost;dbname=demo';
$pdo = new PDO($dsn, 'root', /** ... */);
// ---------------------------------------
// ...then pass it to the PdoSource ---
$source = new PdoSource($pdo);
// ------------------------------------
// ...
php
// index.php
use Rougin\Authsum\Source\PdoSource;
// ...
$source = new PdoSource($pdo);
$source->setTableName('users');
// ...
php
// index.php
use Rougin\Authsum\Source\PdoSource;
// ...
$source = new PdoSource($pdo);
$source->withoutHash();
// ...
php
// index.php
use Rougin\Authsum\Source\JwtSource;
// ...
/** @var \Rougin\Authsum\Source\JwtParserInterface */
$parser = /** ... */;
$source = new JwtSource($parser);
php
namespace Rougin\Authsum\Source;
interface JwtParserInterface
{
/**
* Parses the token string.
*
* @param string $token
*
* @return array<string, mixed>
*/
public function parse($token);
}
php
// index.php
use Rougin\Authsum\Authsum;
use Rougin\Authsum\Source\JwtSource;
// ...
$source = new JwtSource($parser);
// Search "token" property from the payload ---
$source->setTokenField('token');
// --------------------------------------------
$auth = new Authsum($source);
php
// index.php
use Rougin\Authsum\Authsum;
// ...
$auth = new Authsum($source);
// ...
$auth->setUsernameField('email');
// The $_POST data should contains the ---
// "token" field and the "email" field ---
$valid = $auth->isValid($_POST);
// ---------------------------------------
php
namespace Rougin\Authsum\Source;
interface SourceInterface
{
/**
* Returns the error after validation.
*
* @return \Rougin\Authsum\Error
*/
public function getError();
/**
* Returns the result after validation.
*
* @return \Rougin\Authsum\Result
*/
public function getResult();
/**
* Checks if it exists from the source.
*
* @return boolean
*/
public function isValid();
}
php
namespace Rougin\Authsum\Source;
interface WithUsername
{
/**
* Sets the username field.
*
* @param string $username
*
* @return self
*/
public function setUsernameField($username);
/**
* Sets the username.
*
* @param string $username
*
* @return self
*/
public function setUsernameValue($username);
}
php
namespace Rougin\Authsum\Source;
interface WithPassword
{
/**
* Sets the password field.
*
* @param string $password
*
* @return self
*/
public function setPasswordField($password);
/**
* Sets the password value.
*
* @param string $password
*
* @return self
*/
public function setPasswordValue($password);
}
php
namespace Rougin\Authsum\Source;
interface WithPayload
{
/**
* Sets the prepared payload.
*
* @param array<string, string> $payload
*
* @return self
*/
public function setPayload($payload);
}
bash
$ composer global
bash
$ cd Sample
$ php-cs-fixer fix --config=phpstyle.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.