You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
<?php
|
|
namespace config;
|
|
|
|
use Exception;
|
|
|
|
class Validation
|
|
{
|
|
private static $passwordMinLen = 12;
|
|
|
|
public static function val_action($action): string {
|
|
$safeAction = htmlspecialchars($action, ENT_QUOTES);
|
|
if ($safeAction != $action)
|
|
throw new Exception("tentative d'injection sql détectée");
|
|
else return $safeAction;
|
|
}
|
|
|
|
public static function val_password($value): string {
|
|
if ($value == null || !preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)(?!.*\s).{' . Validation::$passwordMinLen . ',}$/', $value))
|
|
throw new Exception("invalid password format");
|
|
return $value;
|
|
}
|
|
|
|
public static function filter_int($value): int {
|
|
if ($value == null || !filter_var($value, FILTER_VALIDATE_INT) || $value < 0)
|
|
throw new Exception("invalid field");
|
|
return $value;
|
|
}
|
|
|
|
public static function filter_str_simple($value): string {
|
|
if ($value == null || !preg_match('/^[A-Za-z\s\-]+$/', $value))
|
|
throw new Exception("invalid field");
|
|
return $value;
|
|
}
|
|
|
|
public static function filter_str_nospecialchar($value): string {
|
|
if ($value == null || !preg_match('/^[A-Za-z0-9\s\-]+$/', $value))
|
|
throw new Exception("invalid field");
|
|
return $value;
|
|
}
|
|
|
|
public static function val_form(string &$nom, string &$age, &$dVueEreur)
|
|
{
|
|
if (!isset($nom) || $nom == '') {
|
|
$dVueEreur[] = 'pas de nom';
|
|
$nom = '';
|
|
}
|
|
|
|
if ( strlen(htmlspecialchars($nom, ENT_QUOTES)) != strlen($nom) ) {
|
|
$dVueEreur[] = "testative d'injection de code (attaque sécurité)";
|
|
$nom = '';
|
|
}
|
|
|
|
if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) {
|
|
$dVueEreur[] = "pas d'age ";
|
|
$age = 0;
|
|
}
|
|
}
|
|
}
|