Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added captcha to the login page #617

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Login/index1.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ <h1 style="color: #f09819; margin-bottom: 2rem;">Activate Your Account</h1>
<input type="password" id="passwordSignIn" placeholder="Password">
<a href="#" class="icon password-toggle" id="togglePasswordSignIn"><i class="fas fa-eye"></i></a>
</div>
<div class="captcha-container">
<span id="captcha-text" class="captcha-text">ABCD</span>
<button type="button" id="refresh-captcha" class="refresh-captcha">
<i class="fas fa-sync-alt"></i>
</button>
</div>
<input type="text" id="captcha-input" placeholder="Enter CAPTCHA" required>

<a href="https://sk66641.github.io/Random-Disco-Light-Simulator/">Forget Your Password?</a>
<button type="submit">Sign In</button>
</form>
Expand Down
30 changes: 30 additions & 0 deletions Login/script1.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,33 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
});

document.addEventListener('DOMContentLoaded', function() {
const captchaText = document.getElementById('captcha-text');
const captchaInput = document.getElementById('captcha-input');
const refreshCaptchaBtn = document.getElementById('refresh-captcha');
const signInForm = document.querySelector('.form-container.sign-in form');

function generateCaptcha() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let captcha = '';
for (let i = 0; i < 6; i++) {
captcha += characters.charAt(Math.floor(Math.random() * characters.length));
}
captchaText.textContent = captcha;
}

refreshCaptchaBtn.addEventListener('click', generateCaptcha);

signInForm.addEventListener('submit', function(event) {
const enteredCaptcha = captchaInput.value;
if (enteredCaptcha !== captchaText.textContent) {
event.preventDefault();
alert('CAPTCHA does not match. Please try again.');
generateCaptcha(); // Generate new CAPTCHA on failed attempt
}
});

// Generate initial CAPTCHA on page load
generateCaptcha();
});
42 changes: 42 additions & 0 deletions Login/styles1.css
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,45 @@ body {
color: white;
transition: all ease-in 0.1s;
}


.captcha-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
width: 100%;
}

.captcha-text {
font-size: 1rem;
font-weight: bold;
color: #f09819;
padding: 0.5rem;
background-color: #333;
border-radius: 5px;
flex: 1;
text-align: center;
margin-right: 10px;
}

.refresh-captcha {
background-color: transparent;
border: none;
cursor: pointer;
font-size: 1.5rem;
color: #f09819;
}

.refresh-captcha:hover {
color: #ffba08;
}

#captcha-input {
width: 100%;
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 1rem;
font-size: 1rem;
}
Loading