-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
161 lines (155 loc) · 4.99 KB
/
Code
File metadata and controls
161 lines (155 loc) · 4.99 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Captcha Form</title>
<style>
* {
margin:0px;
padding:0px;
box-sizing:border-box;
}
body {
font-family:"Roboto", sans-serif;
background:#f5f5f5;
}
.login-form {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
width:90%;
max-width:450px;
background:#fff;
padding:20px 30px;
box-shadow:0px 5px 10px rgba(0,0,0,0.1);
}
.login-form .form-title {
font-family: "Montserrat", sans-serif;
text-align:center;
font-size:30px;
font-weight:600;
margin:20px 0px 30px;
color:#111;
}
.login-form .form-input {
margin:10px 0px;
}
.login-form .form-input label,
.login-form .captcha label {
display:block;
font-size:15px;
color:#111;
margin-bottom:5px;
}
.login-form .form-input input {
width:100%;
padding:10px;
border:1px solid #888;
font-size:15px;
}
.login-form .captcha {
margin:15px 0px;
}
.login-form .captcha .preview {
color:#555;
width:100%;
text-align:center;
height:40px;
line-height:40px;
letter-spacing:8px;
border:1px solid #888;
font-family:"monospace";
}
.login-form .captcha .captcha-form {
display:flex;
}
.login-form .captcha .captcha-form input {
width:100%;
padding:8px;
border:1px solid #888;
}
.login-form .captcha .captcha-form .captcha-refresh {
width:40px;
border:none;
outline:none;
background:#888;
color:#eee;
cursor:pointer;
}
.login-form #login-btn {
margin-top:5px;
width:100%;
padding:10px;
border:none;
outline:none;
font-size:15px;
text-transform:uppercase;
background:#4c81ff;
color:#fff;
cursor:pointer;
}
</style>
</head>
<body>
<div class="login-form">
<div class="form-title">Member Login</div>
<div class="form-input">
<label for="username">Username</label>
<input type="text" id="username">
</div>
<div class="form-input">
<label for="password">Password</label>
<input type="password" id="password">
</div>
<div class="captcha">
<label for="captcha-input">Enter Captcha</label>
<div class="preview"></div>
<div class="captcha-form">
<input type="text" id="captcha-input" placeholder="Enter captcha text">
<button class="captcha-refresh"><i class="fa fa-refresh"></i></button>
</div>
</div>
<div class="form-input">
<button id="login-btn">Login</button>
</div>
</div>
<script>
(function() {
const fonts = ["cursive", "sans-serif", "serif", "monospace"];
let captchaValue = "";
function generateCaptcha() {
let value = btoa(Math.random() * 1000000000);
value = value.substr(0, 5 + Math.random() * 5);
captchaValue = value;
}
function setCaptcha() {
let html = captchaValue.split("").map((char) => {
const rotate = -20 + Math.trunc(Math.random() * 30);
const font = Math.trunc(Math.random() * fonts.length);
return <span style="transform:rotate(${rotate}deg); font-family:${fonts[font]};">${char}</span>;
}).join("");
document.querySelector(".login-form .captcha .preview").innerHTML = html;
}
function initCaptcha() {
document.querySelector(".login-form .captcha .captcha-refresh").addEventListener("click", function() {
generateCaptcha();
setCaptcha();
});
generateCaptcha();
setCaptcha();
}
initCaptcha();
document.querySelector(".login-form #login-btn").addEventListener("click", function() {
let inputCaptchaValue = document.querySelector(".login-form .captcha-form #captcha-input").value;
if (inputCaptchaValue === captchaValue) {
alert("Logging In!");
} else {
alert("Invalid captcha");
}
});
})();
</script>
</body>
</html>