orglman/fundamental

A reposotory of fundamental features that are used in Orgelman's project.

0.0.5 2021-01-10 13:51 UTC

This package is auto-updated.

Last update: 2024-10-21 21:06:07 UTC


README

Build Status composer.lock available

Latest Stable Version Latest Unstable Version Latest Stable Version

star this repo fork this repo Pending Pull-Requests Open Issues

Total Downloads

License

A reposotory of fundamental features that are used in Orgelman's project.

Disclaimer

In the words of Abraham Lincoln:

Pardon my French

My English and technical language in the code is NOT on point... Sorry for any confusion.

Install

OFS is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install OFS. Just add this line to your composer.json file:

"orglman/fundamental": "@dev"

or run

composer require orglman/fundamental

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of OFS.

Code Examples

Forbid direct access

if((isset($_SERVER["SCRIPT_FILENAME"]))&&(basename(__FILE__)==basename($_SERVER["SCRIPT_FILENAME"]))){header($_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized',true,401);header('Status: '.'401 Unauthorized');header('Retry-After: 86400');die('<h1>401 Unauthorized</h1>');}
if(get_included_files()[0]==__FILE__){header($_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized', true, 401);header('Status: '.'401 Unauthorized');header('Retry-After: 86400');die('<h1>401 Unauthorized</h1>');}

Getting script elapsed time

$functions        = new \orgelman\fundamental\scripts\functions($root = null, $start = microtime(true));
echo $functions->timeElapsed();

Hide emails

$functions        = new \orgelman\fundamental\scripts\functions();
echo $functions->obfuscate_email('test@example.com');
echo $functions->botTrap('test@example.com');

Get user agent, IP and client info

$functions        = new \orgelman\fundamental\scripts\functions();
print_r($functions->get_client());
echo $functions->get_client_ua();
echo $functions->get_client_ip();

Encrypting and decrypting strings

$str              = 'message';
$encrypt          = new orgelman\fundamental\security\encrypt($compress = 'true','sha256');
$encrypted        = $encrypt->encrypt($str, $key, $method = '')['encrypted'];

$decrypted        = $encrypt->decrypt($encrypted, $key, $method = '')['decrypted'];

Test passwords

$hash             = new orgelman\fundamental\security\hash($compress = 'true');
$password         = 'password';

$hash->setPasswordLenghtMin($num);
$hash->setPasswordLenghtMax($num);
$hash->setPasswordNumber($num);
$hash->setPasswordLetter($num);
$hash->setPasswordCapital($num);
$hash->setPasswordSymbol($num);

$test = $hash->test($password);
if($test!=true) {
   echo '<ul>';
   foreach(test as $error) {
      echo '<li>'.$error.'</li>';
   }
   echo '</ul>';
}

Hashing and validating passwords

$password         = 'password';
$hash             = new orgelman\fundamental\security\hash($compress = 'true');
$hash->setPasswordLenghtMin($num); // Password minimum lenght
$hash->setPasswordLenghtMax($num); // Password maximum lenght
$hash->setPasswordNumber($num); // How many numbers the password must contain
$hash->setPasswordLetter($num); // How many letters the password must contain
$hash->setPasswordCapital($num); // How many CAPS the password must contain
$hash->setPasswordSymbol($num); // How many symbols the password must contain
$hash->setPasswordStrength($num); // How strong the password must be (0-4)

$hashedPass       = $hash->generate($password);
if(!is_string($hashedPass)) {
   echo '<ul>';
   foreach(hashedPass as $error) {
      echo '<li>'.$error.'</li>';
   }
   echo '</ul>';
} else {
  if($hash->valid(password, $hashedPass)) {
    echo 'Yay!';
  } else {
    echo 'Nay!';
  }
}

Tests

There is a PHPUnit test script in the test folder.

Build status: Build Status

If this isn't passing, is there something you can do to help?

Authors

  • Tobias Jonson - Developer - orglman

License

This project is licensed under the MIT License - see the LICENSE.md file for details