Elgg  Version 3.0
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
ElggCrypto Class Reference

Cryptographic services. More...

Public Member Functions

 getRandomString ($length, $chars=null)
 Generate a random string of specified length. More...
 
 areEqual ($str1, $str2)
 Are two strings equal (compared in constant time)? More...
 

Public Attributes

const CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789'
 Character set for temp passwords (no risk of embedded profanity/glyphs that look similar) More...
 
const CHARS_HEX = '0123456789abcdef'
 Character set for hexadecimal. More...
 

Protected Member Functions

 strlen ($binary_string)
 Count the number of bytes in a string. More...
 

Detailed Description

Cryptographic services.

Definition at line 8 of file ElggCrypto.php.

Member Function Documentation

ElggCrypto::areEqual (   $str1,
  $str2 
)

Are two strings equal (compared in constant time)?

Parameters
string$str1First string to compare
string$str2Second string to compare
Returns
bool

Based on password_verify in PasswordCompat

Author
Anthony Ferrara ircma.nosp@m.xell.nosp@m.@php..nosp@m.net http://www.opensource.org/licenses/mit-license.html MIT License

Definition at line 89 of file ElggCrypto.php.

ElggCrypto::getRandomString (   $length,
  $chars = null 
)

Generate a random string of specified length.

Uses supplied character list for generating the new string. If no character list provided - uses Base64 URL character set.

Parameters
int$lengthDesired length of the string
string | null$charsCharacters to be chosen from randomly. If not given, the Base64 URL charset will be used.
Returns
string The random string
Exceptions
InvalidArgumentException
See also
https://github.com/zendframework/zf2/blob/master/library/Zend/Math/Rand.php#L179

Definition at line 39 of file ElggCrypto.php.

ElggCrypto::strlen (   $binary_string)
protected

Count the number of bytes in a string.

We cannot simply use strlen() for this, because it might be overwritten by the mbstring extension. In this case, strlen() will count the number of characters based on the internal encoding. A sequence of bytes might be regarded as a single multibyte character.

Use elgg_strlen() to count UTF-characters instead of bytes.

Parameters
string$binary_stringThe input string
Returns
int The number of bytes

From PasswordCompat

Author
Anthony Ferrara ircma.nosp@m.xell.nosp@m.@php..nosp@m.net http://www.opensource.org/licenses/mit-license.html MIT License

Definition at line 122 of file ElggCrypto.php.

Member Data Documentation

const ElggCrypto::CHARS_HEX = '0123456789abcdef'

Character set for hexadecimal.

Definition at line 18 of file ElggCrypto.php.

const ElggCrypto::CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789'

Character set for temp passwords (no risk of embedded profanity/glyphs that look similar)

Definition at line 13 of file ElggCrypto.php.


The documentation for this class was generated from the following file: