How to userandom_bytes() function. (Cryptographically Secure) in PHP
The random_bytes() function generates cryptographically secure pseudo-random bytes, which can later be converted to hexadecimal format using bin2hex() function.
Example :
<?php
$n = 20;
$result = bin2hex(random_bytes($n));
echo $result;
?>
Output
67de19022831ea109df3ab3b483a2c0912005fdc
Generating Random String Using PHP
Generate a random, unique, alpha-numeric string using PHP. Examples:
EA070
aBX32gTf
Table of Content
- Brute Force
- Using Hashing Functions
- Using uniqid() function
- Using random_bytes() function. (Cryptographically Secure)
- Using random_int() in a Custom Function