Coder Social home page Coder Social logo

password-checker-php's Introduction

Password checker

Build Status Maintainability Test Coverage

This package helps you to make it easier to check whether a user is using a risky password.

Installation and usage

You can use composer to install the package.

composer require andybeak/password-checker-php

It can be used like this:

use AndyBeak\PasswordChecker\PasswordChecker;
$passwordStrength = PasswordChecker::checkPassword('password');

The class returns an associative array that you can use to decide whether a password matches your password policy. The return value for the example given is:

array (size=6)
  'passwordLength' => int 8
  'containsDigits' => boolean false
  'containsSpecialChars' => boolean false
  'containsUpperAndLower' => boolean true
  'couldPossiblyBeAPassphrase' => boolean false
  'minimumDistanceToBadPassword' => int 1

minimumDistanceToBadPassword

This is the shortest levenshtein distance between the supplied password and all of the dictionary passwords.

If this value is 0 then the supplied password exists as an exact string in the dictionary. This means that it will be possible to brute force guess the password using the supplied dictionary.

There may or may not be value in setting a minimum acceptable distance to a bad password. It's possible that people who are blocked from using password1234 as their password will try password12345, for example.

See [https://www.php.net/manual/en/function.levenshtein.php](The PHP manual) for more details

couldPossiblyBeAPassphrase

This is a very naive stab in the dark that the user could be entering a passphrase. Most password managers seem to avoid including space characters in their generated passwords. Therefore if a user types in a lengthy password (currently 20 characters) that only includes printable characters and includes at least one space then this flag will be set to true.

For example, the output for passphrases are better than passwords is:

array (size=6)
  'passwordLength' => int 37
  'containsDigits' => boolean false
  'containsSpecialChars' => boolean true
  'containsUpperAndLower' => boolean true
  'couldPossiblyBeAPassphrase' => boolean true
  'minimumDistanceToBadPassword' => int 23

Note that only ASCII characters from 32 to 126 are considered printable

You might be willing to relax your policy about special characters and digits if the password supplied looks like a passphrase.

Password list

I include the phpbb password list from (https://wiki.skullsecurity.org/Passwords) in the package. You can replace it with any plaintext file that uses newlines to separate passwords.

Running the tests

Install the composer dependencies using composer install in the package path and then run ./vendor/bin/phpunit to run the tests.

password-checker-php's People

Contributors

andybeak avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.