Token ===== * Published: 2019-08-21 * Author: Nickolas Burr .. contents:: Table of Contents :local: Description ----------- Magento provides the ``Magento\Framework\Math\Random`` [#ref1]_ class for generating random data. This class is particularly useful when you need things like tokens, nonces, and salts, and is used in several areas of the framework. However, we'd prefer to have an entirely static class that provides the same functionality, which we can do with PHP builtins. In the example below, the ``Token`` class provides two ``static`` methods: + ``generate`` + ``isHex`` The ``generate`` method utilizes ``random_bytes`` [#ref2]_ for random sequence generation, and the ``isHex`` method verifies the given sequence contains only hexidecimal characters. Usage ----- .. code-block:: php