1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-27 09:34:45 +02:00

Extract class 'Base64' into external library

This commit is contained in:
Marco
2017-07-24 21:56:35 +02:00
parent b1ac859fd2
commit c2ab825354
5 changed files with 47 additions and 37 deletions

View File

@@ -8,6 +8,7 @@
namespace Delight\Auth;
use Delight\Base64\Base64;
use Delight\Cookie\Cookie;
use Delight\Cookie\Session;
use Delight\Db\PdoDatabase;
@@ -1154,7 +1155,7 @@ final class Auth extends UserManager {
private static function hash($data) {
$hashRaw = hash(self::IP_ADDRESS_HASH_ALGORITHM, $data, true);
return base64_encode($hashRaw);
return Base64::encode($hashRaw);
}
/**

View File

@@ -1,34 +0,0 @@
<?php
/*
* PHP-Auth (https://github.com/delight-im/PHP-Auth)
* Copyright (c) delight.im (https://www.delight.im/)
* Licensed under the MIT License (https://opensource.org/licenses/MIT)
*/
namespace Delight\Auth;
final class Base64 {
const SPECIAL_CHARS_ORIGINAL = '+/=';
const SPECIAL_CHARS_SAFE = '-_~';
public static function encode($data, $safeChars = false) {
$result = base64_encode($data);
if ($safeChars) {
$result = strtr($result, self::SPECIAL_CHARS_ORIGINAL, self::SPECIAL_CHARS_SAFE);
}
return $result;
}
public static function decode($data) {
$data = strtr($data, self::SPECIAL_CHARS_SAFE, self::SPECIAL_CHARS_ORIGINAL);
$result = base64_decode($data, true);
return $result;
}
}

View File

@@ -8,6 +8,7 @@
namespace Delight\Auth;
use Delight\Base64\Base64;
use Delight\Db\PdoDatabase;
use Delight\Db\PdoDsn;
use Delight\Db\Throwable\Error;
@@ -45,7 +46,7 @@ abstract class UserManager {
$data = openssl_random_pseudo_bytes($bytes);
// return the Base64-encoded result
return Base64::encode($data, true);
return Base64::encodeUrlSafe($data);
}
/**