1. Go to this page and download the library: Download oire/iridium 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/ */
oire / iridium example snippets
use Oire\Iridium\Base64;
use Oire\Iridium\Exception\Base64Exception;
$text = "The quick brown fox jumps over the lazy dog";
$encoded = Base64::encode($text);
echo $encoded.PHP_EOL;
use Oire\Iridium\Exception\PasswordException;
use Oire\Iridium\Key\SharedKey;
use Oire\Iridium\Password;
// You should have $key somewhere in an environment variable
$sharedKey = new SharedKey($key);
try {
$storeMe = Password::lock($_POST['password'], $sharedKey);
} catch (PasswordException $e) {
// Handle errors
}
try {
$isPasswordValid = Password::check($_POST['password'], $hashFromDatabase, $sharedKey);
} catch (PasswordException $e) {
// Handle errors. Something went wrong: most often it's a wrong or corrupted key
}
if ($isPasswordValid) {
// OK
} else {
// Wrong password
}
if (Password::needsRehash($hashFromDatabase, $sharedKey)) {
// Re-lock the password with the same key
$newHash = Password::lock($_POST['password'], $sharedKey);
// Store $newHash in the database
}
use Oire\Iridium\Storage\PdoTokenStorage;
$storage = new PdoTokenStorage($pdoConnection);
// Or with a custom table name:
$storage = new PdoTokenStorage($pdoConnection, 'my_tokens_table');
use Oire\Iridium\Storage\DoctrineDbalTokenStorage;
$storage = new DoctrineDbalTokenStorage($dbalConnection);
// From Doctrine ORM:
$storage = new DoctrineDbalTokenStorage($entityManager->getConnection());
use Oire\Iridium\SplitToken;
use Oire\Iridium\Storage\PdoTokenStorage;
// You should have set your $dbConnection first as a PDO instance
$storage = new PdoTokenStorage($dbConnection);
$splitToken = SplitToken::create(
storage: $storage,
expirationTime: time() + 1800,
userId: 123,
tokenType: 3,
additionalInfo: '{"some": "data"}'
)
->persist();
use Oire\Iridium\Exception\InvalidTokenException;
use Oire\Iridium\SplitToken;
try {
$splitToken = SplitToken::fromString($token, $storage);
} catch (InvalidTokenException $e) {
// The token is invalid, not found, tampered with, expired or revoked
}
$splitToken = SplitToken::fromString($token, $storage, allowExpired: true);
if ($splitToken->isExpired()) {
printf('This link expired on %s.', $splitToken->getExpirationDateFormatted());
}
// Given that $splitToken contains a valid token
$splitToken = $splitToken->revokeToken(true);
SplitToken::revokeBySelector($storage, $selector);
// Or, to delete the row rather than expire it:
SplitToken::revokeBySelector($storage, $selector, true);