-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.html
More file actions
172 lines (142 loc) · 6.9 KB
/
password.html
File metadata and controls
172 lines (142 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!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 Mots de Passe</title>
<style>
body { font-family: sans-serif; background-color: #f4f4f9; display: flex; justify-content: center; padding: 20px; }
.card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); width: 100%; max-width: 500px; }
h2 { color: #333; margin-top: 0; }
.field { margin-bottom: 15px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
label { font-size: 0.9rem; color: #555; flex: 1; }
input[type="number"] { width: 60px; padding: 5px; }
button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; margin-top: 10px; }
button:hover { background: #0056b3; }
#results { margin-top: 20px; background: #eee; padding: 10px; border-radius: 4px; white-space: pre-wrap; word-break: break-all; font-family: monospace; min-height: 40px; }
/* Styles pour les caractères spéciaux */
details { border: 1px solid #ddd; border-radius: 4px; padding: 10px; margin-bottom: 15px; }
summary { cursor: pointer; font-weight: bold; font-size: 0.9rem; color: #555; margin-bottom: 10px; }
.symbols-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; margin-top: 10px; }
.symbol-item { display: flex; flex-direction: column; align-items: center; font-size: 0.8rem; background: #f9f9f9; padding: 5px; border-radius: 3px; }
.symbol-actions { margin-top: 10px; display: flex; gap: 10px; }
.btn-small { padding: 4px 8px; font-size: 0.75rem; background: #6c757d; width: auto; margin: 0; }
</style>
</head>
<body>
<div class="card">
<h2>Générateur de Mots de Passe</h2>
<div class="field">
<label>Avec des chiffres (123...)</label>
<input type="checkbox" id="numbers" checked>
</div>
<div class="field">
<label>Avec des lettres minuscules (abc...)</label>
<input type="checkbox" id="lowercase" checked>
</div>
<div class="field">
<label>Avec des lettres majuscules (ABC...)</label>
<input type="checkbox" id="uppercase" checked>
</div>
<div class="field">
<label>Exclure caractères similaires (iI1lLo0O)</label>
<input type="checkbox" id="excludeSimilar">
</div>
<hr>
<details>
<summary>Personnaliser les caractères spéciaux</summary>
<div class="symbol-actions">
<button class="btn-small" onclick="toggleAllSymbols(true)">Tout cocher</button>
<button class="btn-small" onclick="toggleAllSymbols(false)">Tout décocher</button>
</div>
<div id="symbolsContainer" class="symbols-grid">
</div>
</details>
<div class="field">
<label>Nombre de caractères spéciaux</label>
<input type="number" id="symbolCount" value="2" min="0" max="20">
</div>
<div class="field">
<label>Longueur totale</label>
<input type="number" id="length" value="12" min="4" max="50">
</div>
<div class="field">
<label>Quantité</label>
<input type="number" id="quantity" value="1" min="1" max="50">
</div>
<button onclick="generatePasswords()">Générer</button>
<div id="results">Les mots de passe apparaîtront ici...</div>
</div>
<script>
const ALL_SYMBOLS = "!@#$%^&*()_+~`|}{[]:;?><,./-=".split("");
const symbolsContainer = document.getElementById('symbolsContainer');
// Générer la grille de cases à cocher au chargement
ALL_SYMBOLS.forEach((char, index) => {
const div = document.createElement('div');
div.className = 'symbol-item';
div.innerHTML = `
<span>${char}</span>
<input type="checkbox" class="symbol-checkbox" data-char="${char}" checked>
`;
symbolsContainer.appendChild(div);
});
// Fonction pour tout cocher/décocher
function toggleAllSymbols(state) {
document.querySelectorAll('.symbol-checkbox').forEach(cb => cb.checked = state);
}
function generatePasswords() {
const length = parseInt(document.getElementById('length').value);
const quantity = parseInt(document.getElementById('quantity').value);
const symbolCount = parseInt(document.getElementById('symbolCount').value);
const useNumbers = document.getElementById('numbers').checked;
const useLower = document.getElementById('lowercase').checked;
const useUpper = document.getElementById('uppercase').checked;
const excludeSimilar = document.getElementById('excludeSimilar').checked;
// Récupérer uniquement les symboles cochés
const selectedSymbols = Array.from(document.querySelectorAll('.symbol-checkbox:checked'))
.map(cb => cb.getAttribute('data-char'))
.join('');
let baseCharset = "";
if (useNumbers) baseCharset += "0123456789";
if (useLower) baseCharset += "abcdefghijklmnopqrstuvwxyz";
if (useUpper) baseCharset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (excludeSimilar) {
baseCharset = baseCharset.replace(/[iI1lLo0O]/g, '');
}
if (symbolCount > length) {
alert("Le nombre de symboles ne peut pas dépasser la longueur totale !");
return;
}
if (baseCharset === "" && (symbolCount === 0 || selectedSymbols === "")) {
alert("Veuillez sélectionner au moins une option ou des symboles !");
return;
}
if (symbolCount > 0 && selectedSymbols === "") {
alert("Vous avez demandé des symboles mais aucun n'est coché !");
return;
}
let allPasswords = [];
for (let j = 0; j < quantity; j++) {
let passwordArray = [];
// 1. Ajouter les symboles choisis
for (let i = 0; i < symbolCount; i++) {
passwordArray.push(selectedSymbols[Math.floor(Math.random() * selectedSymbols.length)]);
}
// 2. Compléter le reste
const remainingLength = length - symbolCount;
for (let i = 0; i < remainingLength; i++) {
if (baseCharset === "") {
passwordArray.push(selectedSymbols[Math.floor(Math.random() * selectedSymbols.length)]);
} else {
passwordArray.push(baseCharset[Math.floor(Math.random() * baseCharset.length)]);
}
}
// 3. Mélanger
passwordArray.sort(() => Math.random() - 0.5);
allPasswords.push(passwordArray.join(''));
}
document.getElementById('results').innerText = allPasswords.join('\n');
}
</script>
</body>
</html>