User Tools

Site Tools


informatica:linux:php:generar_contrasenyas

This is an old revision of the document!


 Cadenal_aleatoria($Longitud)
{
	#$Caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
	$Caracteres = 'abcdefghijklmnopqrstuvwxyz1234567890';

	// Length of character list
	$Longitud_caracteres = (strlen($Caracteres) - 1);

	// Start our string
	$Cadena = $Caracteres{rand(0, $Longitud_caracteres)};

	// Generate random string
	for ($i = 1; $i < $Longitud; $i = strlen($Cadena))
	{
		// Grab a random character from our list
		$Caracter = $Caracteres{rand(0, $Longitud_caracteres)};

		// Make sure the same two characters don't appear next to each other
		if ($Caracter != $Cadena{$i - 1}) $Cadena .=  $Caracter;
	}

	// Return the string
	return $Cadena;
}
informatica/linux/php/generar_contrasenyas.1247039602.txt.gz · Last modified: 2015/04/13 20:19 (external edit)