Elgg  Version 5.1
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Elgg\Security\Crypto 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 12 of file Crypto.php.

Member Function Documentation

Elgg\Security\Crypto::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 93 of file Crypto.php.

Elgg\Security\Crypto::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

Definition at line 43 of file Crypto.php.

Elgg\Security\Crypto::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 126 of file Crypto.php.

Member Data Documentation

const Elgg\Security\Crypto::CHARS_HEX = '0123456789abcdef'

Character set for hexadecimal.

Definition at line 22 of file Crypto.php.

const Elgg\Security\Crypto::CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789'

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

Definition at line 17 of file Crypto.php.


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