PHP Classes

File: tests/PasswordLockTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PHP Password Lock   tests/PasswordLockTest.php   Download  
File: tests/PasswordLockTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Password Lock
Hash and encrypt passwords with Bcrypt and SHA2
Author: By
Last change:
Date: 4 years ago
Size: 1,084 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use \
ParagonIE\PasswordLock\PasswordLock;
use \
Defuse\Crypto\Key;
use
PHPUnit\Framework\TestCase;

/**
 * @backupGlobals disabled
 * @backupStaticAttributes disabled
 */
class PasswordLockTest extends TestCase
{
    public function
testHash()
    {
       
$key = Key::createNewRandomKey();

       
$password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
       
       
$this->assertTrue(
           
PasswordLock::decryptAndVerify('YELLOW SUBMARINE', $password, $key)
        );
       
       
$this->assertFalse(
           
PasswordLock::decryptAndVerify('YELLOW SUBMARINF', $password, $key)
        );
    }
   
   
/**
     * @expectedException \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
     */
   
public function testBitflip()
    {
       
$key = Key::createNewRandomKey();
       
$password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
       
$password[0] = (\ord($password[0]) === 0 ? 255 : 0);
       
       
PasswordLock::decryptAndVerify('YELLOW SUBMARINE', $password, $key);
    }
}