Skip to content

Commit f677d94

Browse files
authored
Merge pull request #73 from Kunal-Wani-16/Kunal_Wani
Captcha_Generation
2 parents bdab885 + ef223ef commit f677d94

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

Dynamic_Captcha_Generation/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" type="text/css" href="style.css">
5+
</head>
6+
<body>
7+
<div class="captcha-container">
8+
<div id="captcha"></div>
9+
<input type="text" id="captcha-input" placeholder="Enter CAPTCHA">
10+
<button onclick="validateCaptcha()">Submit</button>
11+
</div>
12+
<div id="captcha-status"></div>
13+
14+
<script src="script.js"></script>
15+
</body>
16+
</html>

Dynamic_Captcha_Generation/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Generate a random CAPTCHA string
2+
function generateCaptcha() {
3+
let captcha = "";
4+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
5+
for (let i = 0; i < 6; i++) { // You can change the number of characters in the CAPTCHA
6+
captcha += characters.charAt(Math.floor(Math.random() * characters.length));
7+
}
8+
return captcha;
9+
}
10+
11+
// Display the generated CAPTCHA
12+
function displayCaptcha() {
13+
const captchaDiv = document.getElementById("captcha");
14+
captchaDiv.textContent = generateCaptcha();
15+
}
16+
17+
// Validate the user's input
18+
function validateCaptcha() {
19+
const userInput = document.getElementById("captcha-input").value;
20+
const captchaDiv = document.getElementById("captcha");
21+
const statusDiv = document.getElementById("captcha-status");
22+
23+
if (userInput === captchaDiv.textContent) {
24+
statusDiv.textContent = "CAPTCHA is correct!";
25+
} else {
26+
statusDiv.textContent = "CAPTCHA is incorrect. Please try again.";
27+
displayCaptcha(); // Refresh the CAPTCHA on incorrect input
28+
}
29+
}
30+
31+
// Initialize CAPTCHA
32+
displayCaptcha();

Dynamic_Captcha_Generation/style.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.captcha-container {
2+
text-align: center;
3+
margin-top: 20px;
4+
}
5+
6+
#captcha {
7+
font-size: 20px;
8+
font-weight: bold;
9+
padding: 10px;
10+
border: 1px solid #000;
11+
display: inline-block;
12+
background-color: #f0f0f0;
13+
}
14+
15+
#captcha-input {
16+
margin: 10px;
17+
padding: 5px;
18+
}
19+
20+
button {
21+
background-color: #0074d9;
22+
color: #fff;
23+
border: none;
24+
padding: 10px 20px;
25+
cursor: pointer;
26+
}
27+
28+
#captcha-status {
29+
margin-top: 10px;
30+
}

0 commit comments

Comments
 (0)