Add Helper class with random username generator method

This commit is contained in:
netkas 2025-03-14 15:25:59 -04:00
parent 53673b596a
commit 748b0b2c37
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

26
tests/Helper.php Normal file
View file

@ -0,0 +1,26 @@
<?php
class Helper
{
/**
* Generates a random username based on the given domain.
*
* @param string $domain The domain to be appended to the generated username.
* @param int $length The length of the random string.
* @param string $prefix The prefix to be appended to the generated username.
* @return string Returns a randomly generated username in the format 'user<randomString>@<domain>'.
*/
public static function generateRandomPeer(string $domain, int $length=16, string $prefix='userTest'): string
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
{
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return sprintf('%s%s@%s', $prefix, $randomString, $domain);
}
}