Ce générateur PHP léger et performant vous permet de créer des clés de sécurité robustes, personnalisables selon vos besoins applicatifs.
random_int pour une sécurité cryptographiqueLicence : Libre (Usage personnel & pro)
Copiez ce code dans un fichier nommé password-generator.php
<?php
/**
* Générateur de mot de passe sécurisé - XeoCoder 2026
*/
function generatePassword($length = 12, $uppercase = true, $numbers = true, $symbols = true) {
$lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
$uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$numberChars = '0123456789';
$symbolChars = '!@#$%^&*()-_=+[]{}<>?,.';
$allChars = $lowercaseChars;
if ($uppercase) $allChars .= $uppercaseChars;
if ($numbers) $allChars .= $numberChars;
if ($symbols) $allChars .= $symbolChars;
$password = '';
$max = strlen($allChars) - 1;
for ($i = 0; $i < $length; $i++) {
$password .= $allChars[random_int(0, $max)];
}
return $password;
}
$generatedPassword = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$length = max(4, min(64, intval($_POST['length'])));
$uppercase = isset($_POST['uppercase']);
$numbers = isset($_POST['numbers']);
$symbols = isset($_POST['symbols']);
$generatedPassword = generatePassword($length, $uppercase, $numbers, $symbols);
}
?>
<!-- Structure HTML -->
<form method="POST">
<input type="number" name="length" value="12">
<button type="submit">GÉNÉRER</button>
</form>
<?php if ($generatedPassword): ?>
<div class="result">
<?= htmlspecialchars($generatedPassword) ?>
</div>
<?php endif; ?>