File size: 3,458 Bytes
b4b32f5
bdd80df
 
 
 
b4b32f5
 
bdd80df
b4b32f5
bdd80df
b4b32f5
 
 
 
bdd80df
 
 
b4b32f5
 
 
 
 
 
bdd80df
b4b32f5
 
 
 
 
 
 
 
 
bdd80df
b4b32f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd80df
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

document.getElementById('loginForm').addEventListener('submit', function(e) {
    e.preventDefault();
    
    // Get form values
    const email = document.getElementById('email').value.trim();
    const password = document.getElementById('password').value.trim();
    const rememberMe = document.getElementById('remember-me').checked;
    const captchaResponse = grecaptcha.getResponse();
    
    // Email validation
    const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    if (!emailRegex.test(email)) {
        alert('Please enter a valid email address');
        return;
    }
    
    // Password validation
    const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
    if (!passwordRegex.test(password)) {
        alert('Password must contain:\n- Minimum 8 characters\n- At least one uppercase letter\n- One lowercase letter\n- One number\n- One special character (@$!%*?&)');
        return;
    }
    
    // CAPTCHA validation
    if (!captchaResponse) {
        alert('Please complete the CAPTCHA');
        return;
    }
    
    // Sanitize inputs
    const sanitizedEmail = DOMPurify.sanitize(email);
    const sanitizedPassword = DOMPurify.sanitize(password);
    
    // Log sanitized values
    console.log('Login attempt with:', { 
        email: sanitizedEmail, 
        password: '********', 
        rememberMe 
    });
    
    // Redirect after validation
    window.location.href = 'index.html';
    // Password strength indicator
    document.getElementById('password').addEventListener('input', function(e) {
        const password = e.target.value;
        const strengthDiv = document.getElementById('password-strength');
        const meter = document.getElementById('strength-meter');
        const feedback = document.getElementById('strength-feedback');
        
        if (password.length > 0) {
            strengthDiv.classList.remove('hidden');
            
            // Calculate strength
            let strength = 0;
            const requirements = [];
            
            if (password.length >= 8) strength += 1;
            else requirements.push('At least 8 characters');
            
            if (/[A-Z]/.test(password)) strength += 1;
            else requirements.push('An uppercase letter');
            
            if (/[a-z]/.test(password)) strength += 1;
            else requirements.push('A lowercase letter');
            
            if (/\d/.test(password)) strength += 1;
            else requirements.push('A number');
            
            if (/[@$!%*?&]/.test(password)) strength += 1;
            else requirements.push('A special character (@$!%*?&)');
            
            // Update meter
            const width = (strength / 5) * 100;
            meter.style.width = `${width}%`;
            
            // Update meter color
            if (strength <= 2) {
                meter.style.backgroundColor = '#ef4444'; // red
            } else if (strength <= 4) {
                meter.style.backgroundColor = '#f59e0b'; // amber
            } else {
                meter.style.backgroundColor = '#10b981'; // green
            }
            
            // Update feedback
            feedback.innerHTML = requirements.length 
                ? 'Missing: ' + requirements.join(', ')
                : 'Strong password!';
        } else {
            strengthDiv.classList.add('hidden');
        }
    });
});