PHP code example of maxoplata / string-thing

1. Go to this page and download the library: Download maxoplata/string-thing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maxoplata / string-thing example snippets


use Maxoplata\StringThing;

$myString = 'This is my string';

// Create a new instance of StringThing with default pattern (['split-halves', 'reverse', 'shift', 'swap-case', 'rotate'])
$myStringThing = new StringThing();

// Encode the string
$encoded = $myStringThing->encode($myString);

// Output the encoded string
print encoded; // "ZN!TJ!TJIuHOJSUT!"

// Decode the string
$decoded = myStringThing->decode($encoded);

// Output the decoded string
print decoded; // "This is my string"

use Maxoplata\StringThing;

$myStringThing1 = new StringThing(['split-halves', 'shift', 'reverse', 'shift', 'swap-case', 'rotate']);

// OR

$stringThingPattern = ['split-halves', 'shift', 'reverse', 'shift', 'swap-case', 'rotate'];
$myStringThing2 = new StringThing($stringThingPattern);

use Maxoplata\StringThing;

$stringThingPattern = ['split-halves', 'shift', 'reverse', 'shift', 'swap-case', 'rotate'];

// The original password to be encoded and hashed
$password = 'myPassword123';

// Encode the password using StringThing
$encodedPassword = (new StringThing($stringThingPattern))->encode($password);

// Hash the encoded password with bcrypt
$hashedPassword = password_hash($encodedPassword, PASSWORD_BCRYPT);

// Add the hashed password to a user object for storage in a database
$user = [
  'username' => 'johndoe',
  'email' => '[email protected]',
  'password' => hashedPassword,
  // other user data...
];

// Add the user object to the database
myDatabase->addUser($user);

use Maxoplata\StringThing;

$stringThingPattern = ['split-halves', 'shift', 'reverse', 'shift', 'swap-case', 'rotate'];

// Retrieve the user's hashed password and salt from the database
$user = $myDatabase->getUserByUsername('johndoe');
$hashedPassword = $user->password;

// The password entered by the user attempting to log in
$passwordAttempt = 'myPassword123';

// Encode the password attempt using StringThing
$encodedPasswordAttempt = (new StringThing($stringThingPattern))->encode($passwordAttempt);

// Hash the encoded password attempt with bcrypt
$hashedPasswordAttempt = password_hash($encodedPasswordAttempt, PASSWORD_BCRYPT);

// Compare the hashed password attempt to the stored hashed password
if ($hashedPasswordAttempt === $hashedPassword) {
  // Passwords match - login successful!
} else {
  // Passwords do not match - login failed
}