Chargement...

Script offert

Astuce du jour : découvrez un outil qui pourrait vous faire gagner du temps dans votre projet !

1. Générateur de mot de passe sécurisé (PHP)

Ce générateur PHP vous permet de créer facilement des mots de passe sécurisés, personnalisables avec longueur, chiffres, majuscules et symboles.


  • Personnalisable (longueur, majuscules, chiffres, symboles)
  • Sans base de données
  • Code source commenté et clair
  • Prêt à intégrer dans n'importe quel projet PHP

Licence : Gratuit pour usage personnel et professionnel - Mention de xeocoder.com appréciée


2.📦 Code source complet :

Copiez ce code PHP dans un fichier nommé password-generator.php :

<?php
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, intval($_POST['length']));
  $uppercase = isset($_POST['uppercase']);
  $numbers = isset($_POST['numbers']);
  $symbols = isset($_POST['symbols']);

  $generatedPassword = generatePassword($length, $uppercase, $numbers, $symbols);
}
?>

<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Générateur de mot de passe</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 20px; background: #f4f4f4; }
    .box { background: white; padding: 20px; border-radius: 8px; max-width: 500px; margin: auto; box-shadow: 0 0 10px #ccc; }
    h2 { text-align: center; }
    form { display: flex; flex-direction: column; gap: 12px; }
    input[type="number"], button { padding: 10px; border-radius: 5px; border: 1px solid #ccc; font-size: 16px; }
    label { display: flex; align-items: center; gap: 8px; }
    button { background-color: #2d89ef; color: white; border: none; cursor: pointer; }
    button:hover { background-color: #1b5eaa; }
    .result { margin-top: 20px; font-weight: bold; background: #eef; padding: 10px; border-radius: 5px; text-align: center; }
  </style>
</head>
<body>
<div class="box">
  <h2>Générateur de mot de passe</h2>
  <form method="POST">
    <label>Longueur : <input type="number" name="length" value="12" min="4" max="64"></label>
    <label><input type="checkbox" name="uppercase" checked> Lettres majuscules</label>
    <label><input type="checkbox" name="numbers" checked> Chiffres</label>
    <label><input type="checkbox" name="symbols" checked> Symboles</label>
    <button type="submit">Générer</button>
  </form>
  <?php if ($generatedPassword): ?>
    <div class="result">
      Votre mot de passe : <br>
      <code><?= htmlspecialchars($generatedPassword) ?></code>
    </div>
  <?php endif; ?>
</div>
</body>
</html>

Publicité