1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-05 07:37:25 +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

@@ -4,6 +4,7 @@
"require": {
"php": ">=5.6.0",
"ext-openssl": "*",
"delight-im/base64": "^1.0",
"delight-im/cookie": "^2.1",
"delight-im/db": "^1.2"
},

43
composer.lock generated
View File

@@ -4,8 +4,49 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "c075bec19490fc0e972be01cdd02d59b",
"content-hash": "8ab7c9ad8ef2bc7d9a6beb27f9bf4df5",
"packages": [
{
"name": "delight-im/base64",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/delight-im/PHP-Base64.git",
"reference": "687b2a49f663e162030a8d27b32838bbe7f91c78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/delight-im/PHP-Base64/zipball/687b2a49f663e162030a8d27b32838bbe7f91c78",
"reference": "687b2a49f663e162030a8d27b32838bbe7f91c78",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Delight\\Base64\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Simple and convenient Base64 encoding and decoding for PHP",
"homepage": "https://github.com/delight-im/PHP-Base64",
"keywords": [
"URL-safe",
"base-64",
"base64",
"decode",
"decoding",
"encode",
"encoding",
"url"
],
"time": "2017-07-24T18:59:51+00:00"
},
{
"name": "delight-im/cookie",
"version": "v2.1.2",

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);
}
/**