Password

This class can be used to validate a password or password like string to certain standards. These can be things like having more than one letter, or having at least a single number.

The class can also be used to "score" a password to certain parameters.

category

Password

package

Password

author

Philip Norton philipnorton42@gmail.com

license

http://www.gnu.org/copyleft/gpl.html GNU General Public License

version

Release: 1.0 04/09/2009

link

https://github.com/philipnorton42/PHP-Password

Methods

Constructor

Password(array $options = array()) 

Arguments

$options

array

An associative array of options.

Validate the password to the defined parameters. If a parameters is not set at runtime then a default value is used.

validatePassword(string $password) : boolean

Arguments

$password

string

The password.

Response

boolean

True if password valid, otherwise false.

Score the password based on the level of security. This function doesn't look at the parameters set up and simply scores based on best practices.

scorePassword(string $password) : mixed

The function first makes sure the password is valid as there is no point in scoring a password that can't be used.

Arguments

$password

string

The password to score.

Response

mixed

Returns an integer score of the password strength.

Use the options set up in the class to create a random password that passes validation. This uses certain practices such as not using the letter o or the number 0 as these can be mixed up.

generatePassword() : string

Response

string

The generated password.

Set multiple options for the object in one go.

setOptions(array $options) : null

Arguments

$options

array

An associative array of options.

Response

null

Get any errors produced through the last validation.

getErrors() : array

Response

array

Get the maximum length of password allowed.

setMaxLength(integer $maxLength) : null

Arguments

$maxLength

integer

The maximum length of password allowed.

Response

null

The maximum character length of the password.

getMaxLength() : integer

Response

integer

The maximum character length of the password.

Get the minimum length of password allowed.

setMinLength(integer $minLength) : null

Arguments

$minLength

integer

The minimum length of password allowed.

Response

null

The minimum character length of the password.

getMinLength() : integer

Response

integer

The minimum character length of the password.

Get the symbols allowed in password.

getAllowedSymbols() : array

Response

array

The allowed symbols array.

An array of symbols that can be included in the password. If an array is not passed to this function then it is not stored.

setAllowedSymbols(array $symbols) : null

Arguments

$symbols

array

An array of symbols that can be included in the password.

Response

null

Set the minimum number of symbols required in the password.

setMinSymbols(integer $minSymbols) : null

Arguments

$minSymbols

integer

The minimum number of symbols.

Response

null

Get the minimum number of symbols required in the password.

getMinSymbols() : integer

Response

integer

The minimum number of symbols.

Set the maximum number of symbols required in the password.

setMaxSymbols(integer $maxSymbols) : null

Arguments

$maxSymbols

integer

The maximum number of symbols.

Response

null

The maximum number of symbols allowed in the password.

getMaxSymbols() : integer

Response

integer

The maximum number of symbols allowed in the password.

Make sure that parameters don't overlap in such a way as to make validation impossible. For example, if the minimum number of letters numbers and symbols allowed is greater than the maximum length of the password then these numbers are added together and used as the new maximum password length.

_sanitizeInputs() : null

Response

null

Properties

Holds an array of any errors encountered whilst validating the password.

errors
var

Holds an array of any errors encountered whilst validating the password.

The minimum number of characters that the password must be.

minLength
var

The minimum number of characters that the password must be.

The maximum number of characters that the password must be.

maxLength
var

The maximum number of characters that the password must be.

The minimum number of numbers that the password should contain.

minNumbers
var

The minimum number of numbers that the password should contain.

The minimum number of letters that the password should contain.

minLetters
var

The minimum number of letters that the password should contain.

The minimum number of lower case letters that the password should contain.

minLowerCase
var

The minimum number of lower case letters that the password should contain.

The minimum number of upper case letters that the password should contain.

minUpperCase
var

The minimum number of upper case letters that the password should contain.

The minimum number of symbols that the password should contain.

minSymbols
var

The minimum number of symbols that the password should contain.

The maximum number of symbols that the password should contain.

maxSymbols
var

The maximum number of symbols that the password should contain.

The symbols that are allowed to be in the password.

allowedSymbols
var

The symbols that are allowed to be in the password.

The score of the password.

score
var

The score of the password.