Skip to content

Instantly share code, notes, and snippets.

@ivolivares
Last active December 23, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivolivares/6621176 to your computer and use it in GitHub Desktop.
Save ivolivares/6621176 to your computer and use it in GitHub Desktop.
Una cadena de texto aleatoria, perfecto para "contraseñas seguras" (sin entropía obviamente).
<?php
/*
* Random String ();
* Developed by: @ivolivares
*
* Uso: randomString(20);
* Donde: 20 = Cantidad de caracteres o el largo total del texto a generar.
*
*/
function randomString($charactersLength = 30) {
$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$randomResult = "";
$length = strlen($characters);
for ($i = 0; $i < $charactersLength; $i++) {
$randomResult .= $characters[rand(0, $length)];
}
return $randomResult;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment