DNSBlock
This commit is contained in:
21
app/Utils/JWT.php
Normal file
21
app/Utils/JWT.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
use Firebase\JWT\JWT as FirebaseJWT;
|
||||
use Firebase\JWT\Key;
|
||||
|
||||
class JWT
|
||||
{
|
||||
public static function encode($payload)
|
||||
{
|
||||
$key = getenv('JWT_SECRET') ?: 'default_secret';
|
||||
return FirebaseJWT::encode($payload, $key, 'HS256');
|
||||
}
|
||||
|
||||
public static function decode($token)
|
||||
{
|
||||
$key = getenv('JWT_SECRET') ?: 'default_secret';
|
||||
return FirebaseJWT::decode($token, new Key($key, 'HS256'));
|
||||
}
|
||||
}
|
||||
20
app/Utils/PasswordValidator.php
Normal file
20
app/Utils/PasswordValidator.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
class PasswordValidator
|
||||
{
|
||||
public static function validate($password)
|
||||
{
|
||||
if (strlen($password) < 8) {
|
||||
return "A senha deve ter pelo menos 8 caracteres.";
|
||||
}
|
||||
if (!preg_match('/[A-Z]/', $password)) {
|
||||
return "A senha deve conter pelo menos uma letra maiúscula.";
|
||||
}
|
||||
if (!preg_match('/[^a-zA-Z0-9]/', $password)) {
|
||||
return "A senha deve conter pelo menos um caractere especial.";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
32
app/Utils/View.php
Normal file
32
app/Utils/View.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
class View
|
||||
{
|
||||
public static function render($view, $data = [])
|
||||
{
|
||||
extract($data);
|
||||
$viewPath = __DIR__ . '/../../resources/views/' . str_replace('.', '/', $view) . '.php';
|
||||
|
||||
if (file_exists($viewPath)) {
|
||||
require $viewPath;
|
||||
} else {
|
||||
echo "View not found: $view";
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect($url)
|
||||
{
|
||||
header("Location: $url");
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function json($data, $status = 200)
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user