1. Go to this page and download the library: Download tbaumgard/yubilib 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/ */
tbaumgard / yubilib example snippets
// Load the library and automatically load classes and dependencies as needed.
= "12345";
$settings["apiKey"] = "IEFQSSBrZXkgaW4gYmFzZTY0IA==";
$settings["server"] = "api.yubico.com";
$settings["timeout"] = 10;
try {
$isOtpValid = yubilib\validateOneTimePasswordRemotely($otp, $settings);
} catch (yubilib\requestTimeoutException $exception) {
// Handle a request that timed out.
} catch (yubilib\badRequestException $exception) {
// Handle a bad request, e.g., invalid server, client ID, or API key.
} catch (yubilib\badResponseException $exception) {
// Handle a bad response, e.g., network or validation server issue.
}
// Load the library and automatically load classes and dependencies as needed.
s["privateIdentity"] = "4ae4e40efa8a";
$credentials["secretKey"] = "637f70b3846347d55ee49016a7da70a2";
$credentials["counter"] = 0;
// Prepare the credentials to get them into the format that
// yubilib\serializeCredentials() and yubilib\validateOneTimePasswordLocally()
// expect. This
// Load the library and automatically load classes and dependencies as needed.
etrieve the stored credentials in serialized format.
$serializedCredentials = example\retriveOneTimePasswordCredentials($userId);
// Deserialize and validate the one-time password.
$credentials = yubilib\deserializeCredentials($serializedCredentials);
list($isOtpValid, $newCounter) = yubilib\validateOneTimePasswordLocally($otp, $credentials);
if ($isOtpValid) {
// Update the counter and serialize the updated credentials.
$credentials["counter"] = $newCounter;
$serializedCredentials = yubilib\serializeCredentials($credentials);
// Save the updated credentials, namely the counter, to prevent replay attacks.
example\storeOneTimePasswordCredentials($userId, $serializedCredentials);
} else {
// Notify the user that the one-time password is invalid.
example\printOneTimePasswordErrorMessage();
}
// Load the library and automatically load classes and dependencies as needed.
ey = "637f70b3846347d55ee49016a7da70a2";
$otp = "kgucftudgcknghjjkunucgldkcvdtfhnbuikidrlnukt";
if (yubilib\isPublicIdentity($publicIdentity, "modhex")) {
// Notify the user that the public identity is invalid.
example\printPublicIdentityErrorMessage();
}
if (yubilib\isPrivateIdentity($privateIdentity, "hex")) {
// Notify the user that the private identity is invalid.
example\printPrivateIdentityErrorMessage();
}
if (yubilib\isSecretKey($secretKey, "hex")) {
// Notify the user that the secret key is invalid.
example\printSecretKeyErrorMessage();
}
if (yubilib\isOneTimePassword($otp, "modhex")) {
// Notify the user that the one-time password is invalid.
example\printOneTimePasswordErrorMessage();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.