PHP Classes

PHP Password Validation: Generate and validate passwords based in rules

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 555 This week: 1All time: 5,479 This week: 560Up
Version License PHP version Categories
password-validation 1.0.1GNU Lesser Genera...5.3PHP 5, Text processing, Validation
Description 

Author

This class can generate and validate passwords based in rules.

It can generate a random password with a given length that match specified rules.

The rules can determine the number of letters, capital letters, numbers and symbols that the password must contain.

The class can also take a given password and validate it determining if it satisfy the specified rules.

Picture of Igor Zaporozhets
  Performance   Level  
Name: Igor Zaporozhets <contact>
Classes: 1 package by
Country: Ukraine Ukraine
Age: 55
All time rank: 315950 in Ukraine Ukraine
Week rank: 416 Up8 in Ukraine Ukraine Up

Example

<?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());
    }


Details

Utility class for password generation and checking. This is utility class for password generation and checking according to custom password policy rules. Password characters may include several subsets of characters: letters (latin and utf-8 as well), digits, symbols. This sets of characters are fully customizable as well as other password generation configuration params: min_length, letters_count, capitals_count, numbers_count, symbols_count. Default password policy check rule is min_length. Another custom ones may be added to class instance by means of regular expressions. See unit test file for usage Unit test provided in ../tests/ directory. Short usage example provided in ../tests/example.php file. Also see unit test file for possible configuration values Public methods usage: see appropriate doc comment.

  Files folder image Files  
File Role Description
Files folder imagetests (2 files)
Plain text file Password.php Class Main class
Accessible without login Plain text file readme.txt Doc. read me file

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file PasswordTest.php Test Test File
  Accessible without login Plain text file example.php Example Short example usage

 Version Control Unique User Downloads Download Rankings  
 0%
Total:555
This week:1
All time:5,479
This week:560Up
User Comments (1)
Thats a good class ;-)
9 years ago (Jos Filipe Lopes Santos)
90%StarStarStarStarStar