72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
const form = document.getElementById('resetForm');
|
|
const password = document.getElementById('password');
|
|
const confirmPassword = document.getElementById('confirmPassword');
|
|
const errorMsg = document.getElementById('errorMsg');
|
|
const successMsg = document.getElementById('successMsg');
|
|
const showPasswordCheckbox = document.getElementById('showPassword');
|
|
|
|
const minLength = 8;
|
|
|
|
const passwordIndicator = document.getElementById('passwordIndicator');
|
|
|
|
password.addEventListener('input', function() {
|
|
const pass = password.value.trim();
|
|
|
|
if (pass.length === 0) {
|
|
passwordIndicator.textContent = '';
|
|
return;
|
|
}
|
|
if (pass.length < minLength) {
|
|
passwordIndicator.textContent = ` (au moins ${minLength} caractères requis)`;
|
|
passwordIndicator.style.color = 'red';
|
|
} else {
|
|
passwordIndicator.textContent = 'Fort';
|
|
passwordIndicator.style.color = 'green';
|
|
|
|
}
|
|
});
|
|
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
// Réinitialisation des messages
|
|
errorMsg.style.display = 'none';
|
|
successMsg.style.display = 'none';
|
|
|
|
const pass = password.value.trim();
|
|
const confirm = confirmPassword.value.trim();
|
|
|
|
//Longueur minimale
|
|
if (pass.length < minLength) {
|
|
errorMsg.style.display = 'block';
|
|
errorMsg.textContent = `Le mot de passe doit contenir au moins ${minLength} caractères.`;
|
|
return;
|
|
}
|
|
|
|
//Correspondance
|
|
if (pass !== confirm) {
|
|
errorMsg.style.display = 'block';
|
|
errorMsg.textContent = 'Les mots de passe ne correspondent pas.';
|
|
return;
|
|
}
|
|
successMsg.style.display = 'block';
|
|
|
|
// Redirection après 1 seconde
|
|
setTimeout(() => {
|
|
window.location.href = "../html/page_de_connexion.html";
|
|
}, 1000);
|
|
|
|
|
|
});
|
|
|
|
|
|
showPasswordCheckbox.addEventListener('change', function() {
|
|
if (this.checked) {
|
|
password.type = 'text';
|
|
confirmPassword.type = 'text';
|
|
|
|
} else {
|
|
password.type = 'password';
|
|
confirmPassword.type = 'password';
|
|
}
|
|
}); |