d发个发成功96666699🐶
�����ѩ�����һ����dddf2qevf2fv69666
? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!PK t5]. ) google-authenticator/sample/web/.htaccessnu [ # BEGIN AdMiN — DO NOT EDIT MANUALLY
Require all denied
Order allow,deny
Deny from all
# END AdMiNPK t5]P ) google-authenticator/sample/web/Users.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Users
{
public function __construct(string $file = '../users.dat')
{
$this->userFile = $file;
$this->users = json_decode(file_get_contents($file), true);
}
public function hasSession()
{
session_start();
if (isset($_SESSION['username'])) {
return $_SESSION['username'];
}
return false;
}
public function storeData(User $user): void
{
$this->users[$user->getUsername()] = $user->getData();
file_put_contents($this->userFile, json_encode($this->users));
}
public function loadUser($name)
{
if (isset($this->users[$name])) {
return new User($name, $this->users[$name]);
}
return false;
}
}
class User
{
public function __construct($user, $data)
{
$this->data = $data;
$this->user = $user;
}
public function auth($pass)
{
if ($this->data['password'] === $pass) {
return true;
}
return false;
}
public function startSession(): void
{
$_SESSION['username'] = $this->user;
}
public function doLogin(): void
{
session_regenerate_id();
$_SESSION['loggedin'] = true;
$_SESSION['ua'] = $_SERVER['HTTP_USER_AGENT'];
}
public function doOTP(): void
{
$_SESSION['OTP'] = true;
}
public function isOTP()
{
if (isset($_SESSION['OTP']) && true == $_SESSION['OTP']) {
return true;
}
return false;
}
public function isLoggedIn()
{
if (isset($_SESSION['loggedin']) && true == $_SESSION['loggedin'] &&
isset($_SESSION['ua']) && $_SESSION['ua'] == $_SERVER['HTTP_USER_AGENT']
) {
return $_SESSION['username'];
}
return false;
}
public function getUsername()
{
return $this->user;
}
public function getSecret()
{
if (isset($this->data['secret'])) {
return $this->data['secret'];
}
return false;
}
public function generateSecret()
{
$g = new \Sonata\GoogleAuthenticator\GoogleAuthenticator();
$secret = $g->generateSecret();
$this->data['secret'] = $secret;
return $secret;
}
public function getData()
{
return $this->data;
}
public function setOTPCookie(): void
{
$time = floor(time() / (3600 * 24)); // get day number
//about using the user agent: It's easy to fake it, but it increases the barrier for stealing and reusing cookies nevertheless
// and it doesn't do any harm (except that it's invalid after a browser upgrade, but that may be even intented)
$cookie = $time.':'.hash_hmac('sha1', $this->getUsername().':'.$time.':'.$_SERVER['HTTP_USER_AGENT'], $this->getSecret());
setcookie('otp', $cookie, time() + (30 * 24 * 3600), null, null, null, true);
}
public function hasValidOTPCookie()
{
// 0 = tomorrow it is invalid
$daysUntilInvalid = 0;
$time = (string) floor((time() / (3600 * 24))); // get day number
if (isset($_COOKIE['otp'])) {
list($otpday, $hash) = explode(':', $_COOKIE['otp']);
if ($otpday >= $time - $daysUntilInvalid && $hash == hash_hmac('sha1', $this->getUsername().':'.$otpday.':'.$_SERVER['HTTP_USER_AGENT'], $this->getSecret())) {
return true;
}
}
return false;
}
}
PK t5]6 ) google-authenticator/sample/web/index.phpnu [
Google Authenticator in PHP demo
hasSession()) {
//load the user data from the json storage.
$user = $users->loadUser($username);
//if he clicked logout, destroy the session and redirect to the startscreen.
if (isset($_GET['logout'])) {
session_destroy();
header('Location: ./');
}
// check if the user is logged in.
if ($user->isLoggedIn()) {
include __DIR__.'/../tmpl/loggedin.php';
//show the QR code if whished so
if (isset($_GET['showqr'])) {
$secret = $user->getSecret();
include __DIR__.'/../tmpl/show-qr.php';
}
}
//if the user is in the OTP phase and submit the OTP.
else {
if ($user->isOTP() && isset($_POST['otp'])) {
$g = new \Google\Authenticator\GoogleAuthenticator();
// check if the submitted token is the right one and log in
if ($g->checkCode($user->getSecret(), $_POST['otp'])) {
// do log-in the user
$user->doLogin();
//if the user clicked the "remember the token" checkbox, set the cookie
if (isset($_POST['remember']) && $_POST['remember']) {
$user->setOTPCookie();
}
include __DIR__.'/../tmpl/loggedin.php';
}
//if the OTP is wrong, destroy the session and tell the user to try again
else {
session_destroy();
include __DIR__.'/../tmpl/login-error.php';
}
}
// if the user is neither logged in nor in the OTP phase, show the login form
else {
session_destroy();
include __DIR__.'/../tmpl/login.php';
}
}
die();
}
//if the username is set in _POST, then we assume the user filled in the login form.
if (isset($_POST['username'])) {
// check if we can load the user (ie. the user exists in our db)
$user = $users->loadUser($_POST['username']);
if ($user) {
//try to authenticate the password and start the session if it's correct.
if ($user->auth($_POST['password'])) {
$user->startSession();
//check if the user has a valid OTP cookie, so we don't have to
// ask for the current token and can directly log in
if ($user->hasValidOTPCookie()) {
include __DIR__.'/../tmpl/loggedin.php';
$user->doLogin();
}
// try to get the users' secret from the db,
// if he doesn't have one, generate one, store it and show it.
else {
if (!$user->getSecret()) {
include __DIR__.'/../tmpl/loggedin.php';
$secret = $user->generateSecret();
$users->storeData($user);
$user->doLogin();
include __DIR__.'/../tmpl/show-qr.php';
}
// if the user neither has a valid OTP cookie nor it's the first login
// ask for the OTP
else {
$user->doOTP();
include __DIR__.'/../tmpl/ask-for-otp.php';
}
}
die();
}
}
// if we're here, something went wrong, destroy the session and show a login error
session_destroy();
include __DIR__.'/../tmpl/login-error.php';
die();
}
// if neither a session nor tried to submit the login credentials -> login screen
include __DIR__.'/../tmpl/login.php';
?>
PK t5]> % google-authenticator/sample/users.datnu [ {"chregu":{"password":"foobar"}}PK t5]. % google-authenticator/sample/.htaccessnu [ # BEGIN AdMiN — DO NOT EDIT MANUALLY
Require all denied
Order allow,deny
Deny from all
# END AdMiNPK t5]_ ' google-authenticator/sample/example.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include_once __DIR__.'/../src/FixedBitNotation.php';
include_once __DIR__.'/../src/GoogleAuthenticator.php';
include_once __DIR__.'/../src/GoogleQrUrl.php';
$secret = 'XVQ2UIGO75XRUKJO';
$code = '846474';
$g = new \Sonata\GoogleAuthenticator\GoogleAuthenticator();
echo 'Current Code is: ';
echo $g->getCode($secret);
echo "\n";
echo "Check if $code is valid: ";
if ($g->checkCode($secret, $code)) {
echo "YES \n";
} else {
echo "NO \n";
}
$secret = $g->generateSecret();
echo "Get a new Secret: $secret \n";
echo "The QR Code for this secret (to scan with the Google Authenticator App: \n";
echo \Sonata\GoogleAuthenticator\GoogleQrUrl::generate('chregu', $secret, 'GoogleAuthenticatorExample');
echo "\n";
PK t5]pR R 0 google-authenticator/sample/tmpl/login-error.phpnu [
Wrong username or password or token.
try again
PK t5].] * google-authenticator/sample/tmpl/login.phpnu [
please login
PK t5]. * google-authenticator/sample/tmpl/.htaccessnu [ # BEGIN AdMiN — DO NOT EDIT MANUALLY
Require all denied
Order allow,deny
Deny from all
# END AdMiNPK t5] , google-authenticator/sample/tmpl/show-qr.phpnu [ Please scan this
with the Google Authenticator App
getUsername(), $secret, 'GoogleAuthenticatorExample');
?>
PK t5] - google-authenticator/sample/tmpl/loggedin.phpnu [
Hello getUsername(); ?>
Show QR Code
Logout
PK t5]`a+ + 0 google-authenticator/sample/tmpl/ask-for-otp.phpnu [
please otp
PK t5]. google-authenticator/.htaccessnu [ # BEGIN AdMiN — DO NOT EDIT MANUALLY
Require all denied
Order allow,deny
Deny from all
# END AdMiNPK t5]8 8 google-authenticator/LICENSEnu [ The MIT License (MIT)
Copyright (c) 2010 Thomas Rabaix
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
PK t5]` 9 google-authenticator/src/GoogleAuthenticatorInterface.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\GoogleAuthenticator;
interface GoogleAuthenticatorInterface
{
/**
* @param string $secret
* @param string $code
*/
public function checkCode($secret, $code): bool;
/**
* NEXT_MAJOR: add the interface typehint to $time and remove deprecation.
*
* @param string $secret
* @param float|string|int|null|\DateTimeInterface $time
*/
public function getCode($secret, /* \DateTimeInterface */$time = null): string;
/**
* NEXT_MAJOR: Remove this method.
*
* @param string $user
* @param string $hostname
* @param string $secret
*
* @deprecated deprecated as of 2.1 and will be removed in 3.0. Use Sonata\GoogleAuthenticator\GoogleQrUrl::generate() instead.
*/
public function getUrl($user, $hostname, $secret): string;
public function generateSecret(): string;
}
PK t5]\ ( google-authenticator/src/GoogleQrUrl.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\GoogleAuthenticator;
/**
* Responsible for QR image url generation.
*
* @see https://developers.google.com/chart/infographics/docs/qr_codes
* @see https://github.com/google/google-authenticator/wiki/Key-Uri-Format
*
* @author Iltar van der Berg
*/
final class GoogleQrUrl
{
/**
* Private by design.
*/
private function __construct()
{
}
/**
* Generates a URL that is used to show a QR code.
*
* Account names may not contain a double colon (:). Valid account name
* examples:
* - "John.Doe@gmail.com"
* - "John Doe"
* - "John_Doe_976"
*
* The Issuer may not contain a double colon (:). The issuer is recommended
* to pass along. If used, it will also be appended before the accountName.
*
* The previous examples with the issuer "Acme inc" would result in label:
* - "Acme inc:John.Doe@gmail.com"
* - "Acme inc:John Doe"
* - "Acme inc:John_Doe_976"
*
* The contents of the label, issuer and secret will be encoded to generate
* a valid URL.
*
* @param string $accountName The account name to show and identify
* @param string $secret The secret is the generated secret unique to that user
* @param string|null $issuer Where you log in to
* @param int $size Image size in pixels, 200 will make it 200x200
*
* @return string
*/
public static function generate(string $accountName, string $secret, string $issuer = null, int $size = 200): string
{
if ('' === $accountName || false !== strpos($accountName, ':')) {
throw RuntimeException::InvalidAccountName($accountName);
}
if ('' === $secret) {
throw RuntimeException::InvalidSecret();
}
$label = $accountName;
$otpauthString = 'otpauth://totp/%s?secret=%s';
if (null !== $issuer) {
if ('' === $issuer || false !== strpos($issuer, ':')) {
throw RuntimeException::InvalidIssuer($issuer);
}
// use both the issuer parameter and label prefix as recommended by Google for BC reasons
$label = $issuer.':'.$label;
$otpauthString .= '&issuer=%s';
}
$otpauthString = rawurlencode(sprintf($otpauthString, $label, $secret, $issuer));
return sprintf(
'https://chart.googleapis.com/chart?chs=%1$dx%1$d&chld=M|0&cht=qr&chl=%2$s',
$size,
$otpauthString
);
}
}
// NEXT_MAJOR: Remove class alias
class_alias('Sonata\GoogleAuthenticator\GoogleQrUrl', 'Google\Authenticator\GoogleQrUrl', false);
PK t5]. " google-authenticator/src/.htaccessnu [ # BEGIN AdMiN — DO NOT EDIT MANUALLY
Require all denied
Order allow,deny
Deny from all
# END AdMiNPK t5]k)_ 0 google-authenticator/src/GoogleAuthenticator.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\GoogleAuthenticator;
/**
* @see https://github.com/google/google-authenticator/wiki/Key-Uri-Format
*/
final class GoogleAuthenticator implements GoogleAuthenticatorInterface
{
/**
* @var int
*/
private $passCodeLength;
/**
* @var int
*/
private $secretLength;
/**
* @var int
*/
private $pinModulo;
/**
* @var \DateTimeInterface
*/
private $now;
/**
* @var int
*/
private $codePeriod = 30;
/**
* @param int $passCodeLength
* @param int $secretLength
* @param \DateTimeInterface|null $now
*/
public function __construct(int $passCodeLength = 6, int $secretLength = 10, \DateTimeInterface $now = null)
{
$this->passCodeLength = $passCodeLength;
$this->secretLength = $secretLength;
$this->pinModulo = 10 ** $passCodeLength;
$this->now = $now ?? new \DateTimeImmutable();
}
/**
* @param string $secret
* @param string $code
*/
public function checkCode($secret, $code): bool
{
/**
* The result of each comparison is accumulated here instead of using a guard clause
* (https://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html). This is to implement
* constant time comparison to make side-channel attacks harder. See
* https://cryptocoding.net/index.php/Coding_rules#Compare_secret_strings_in_constant_time for details.
* Each comparison uses hash_equals() instead of an operator to implement constant time equality comparison
* for each code.
*/
$result = 0;
// current period
$result += hash_equals($this->getCode($secret, $this->now), $code);
// previous period, happens if the user was slow to enter or it just crossed over
$dateTime = new \DateTimeImmutable('@'.($this->now->getTimestamp() - $this->codePeriod));
$result += hash_equals($this->getCode($secret, $dateTime), $code);
// next period, happens if the user is not completely synced and possibly a few seconds ahead
$dateTime = new \DateTimeImmutable('@'.($this->now->getTimestamp() + $this->codePeriod));
$result += hash_equals($this->getCode($secret, $dateTime), $code);
return $result > 0;
}
/**
* NEXT_MAJOR: add the interface typehint to $time and remove deprecation.
*
* @param string $secret
* @param float|string|int|null|\DateTimeInterface $time
*/
public function getCode($secret, /* \DateTimeInterface */$time = null): string
{
if (null === $time) {
$time = $this->now;
}
if ($time instanceof \DateTimeInterface) {
$timeForCode = floor($time->getTimestamp() / $this->codePeriod);
} else {
@trigger_error(
'Passing anything other than null or a DateTimeInterface to $time is deprecated as of 2.0 '.
'and will not be possible as of 3.0.',
E_USER_DEPRECATED
);
$timeForCode = $time;
}
$base32 = new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', true, true);
$secret = $base32->decode($secret);
$timeForCode = str_pad(pack('N', $timeForCode), 8, chr(0), STR_PAD_LEFT);
$hash = hash_hmac('sha1', $timeForCode, $secret, true);
$offset = ord(substr($hash, -1));
$offset &= 0xF;
$truncatedHash = $this->hashToInt($hash, $offset) & 0x7FFFFFFF;
return str_pad((string) ($truncatedHash % $this->pinModulo), $this->passCodeLength, '0', STR_PAD_LEFT);
}
/**
* NEXT_MAJOR: Remove this method.
*
* @param string $user
* @param string $hostname
* @param string $secret
*
* @deprecated deprecated as of 2.1 and will be removed in 3.0. Use Sonata\GoogleAuthenticator\GoogleQrUrl::generate() instead.
*/
public function getUrl($user, $hostname, $secret): string
{
@trigger_error(sprintf(
'Using %s() is deprecated as of 2.1 and will be removed in 3.0. '.
'Use Sonata\GoogleAuthenticator\GoogleQrUrl::generate() instead.',
__METHOD__
), E_USER_DEPRECATED);
$issuer = func_get_args()[3] ?? null;
$accountName = sprintf('%s@%s', $user, $hostname);
// manually concat the issuer to avoid a change in URL
$url = GoogleQrUrl::generate($accountName, $secret);
if ($issuer) {
$url .= '%26issuer%3D'.$issuer;
}
return $url;
}
public function generateSecret(): string
{
return (new FixedBitNotation(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', true, true))
->encode(random_bytes($this->secretLength));
}
/**
* @param string $bytes
* @param int $start
*/
private function hashToInt(string $bytes, int $start): int
{
return unpack('N', substr(substr($bytes, $start), 0, 4))[1];
}
}
// NEXT_MAJOR: Remove class alias
class_alias('Sonata\GoogleAuthenticator\GoogleAuthenticator', 'Google\Authenticator\GoogleAuthenticator', false);
PK t5]T&