PHP Classes

File: tests/example.php

Recommend this page to a friend!
  Classes of Igor Zaporozhets   PHP Password Validation   tests/example.php   Download  
File: tests/example.php
Role: Example script
Content type: text/plain
Description: Short example usage
Class: PHP Password Validation
Generate and validate passwords based in rules
Author: By
Last change: Move to tests dir
Date: 9 years ago
Size: 1,523 bytes
 

Contents

Class file image Download
<?php

namespace Security;
require_once
__DIR__ . '/../Password.php';

   
header('Content-Encoding: UTF-8');
   
$pu = new Password();
    try
    {
       
$min_length = 7;
       
$password='Слава Україні';
       
$check = $pu->letters(array(
                   
'а', 'б', 'в', 'г', 'ґ', 'д ', 'е', 'є', 'ж',
                   
'з', 'и', 'і', 'ї', 'й', 'к', 'л', 'м', 'н',
                   
'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц',
                   
'ч', 'ш', 'щ', 'ь', 'ю', 'я',
                   
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                   
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                   
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
               
))
                ->
min_length($min_length)
                ->
letters_count(12)
                ->
symbols_count(0)
                ->
capitals_count(3)
                ->
numbers_count(0)
                ->
password($password)
                ->
password_policy(array(
                   
'contains_lowercase' => array(
                       
'regex' => '[a-z\x{0430}-\x{045f}]+'),)
                )
                ->
check();
        print
$password;
        if(
$pu->has_errors())
        {
           
var_dump($pu->get_errors());
        }
        else
        {
           
var_dump('Pwd OK. Entropy');
           
var_dump($pu->entropy());
        }
    }
    catch(\
Exception $e)
    {
       
var_dump($e->getMessage());
    }