File tree Expand file tree Collapse file tree
30DaysOfJavaScript/assets Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Custom Captcha Generator</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ < link
9+ rel ="shortcut icon "
10+ href ="assets/favicon.ico "
11+ type ="image/x-icon "
12+ />
13+ < link
14+ rel ="stylesheet "
15+ href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css "
16+ />
17+ </ head >
18+ < body >
19+ < div class ="cover ">
20+ < header > CAPTCHA GENERATOR</ header >
21+ < div class ="captcha-box ">
22+ < div class ="captcha-img ">
23+ < img src ="assets/bg6.png " alt ="Captch Background " />
24+ < span class ="captcha "> </ span >
25+ </ div >
26+ < button class ="reload ">
27+ < i class ="fas fa-redo-alt "> </ i >
28+ </ button >
29+ </ div >
30+ < form action ="# " class ="input-text ">
31+ < input
32+ type ="text "
33+ placeholder ="Enter captcha "
34+ maxlength ="6 "
35+ spellcheck ="false "
36+ required
37+ />
38+ < button class ="verify "> Check</ button >
39+ </ form >
40+ < div class ="result "> </ div >
41+ </ div >
42+
43+ < script src ="script.js "> </ script >
44+ </ body >
45+ </ html >
Original file line number Diff line number Diff line change 1+ const captcha = document . querySelector ( '.captcha' ) ,
2+ reloadbtn = document . querySelector ( '.reload' ) ,
3+ inputText = document . querySelector ( '.input-text input' ) ,
4+ verifyBtn = document . querySelector ( '.verify' ) ,
5+ responseTxt = document . querySelector ( '.result' ) ;
6+
7+ let characters = [
8+ 'A' ,
9+ 'B' ,
10+ 'C' ,
11+ 'D' ,
12+ 'E' ,
13+ 'F' ,
14+ 'G' ,
15+ 'H' ,
16+ 'I' ,
17+ 'J' ,
18+ 'K' ,
19+ 'L' ,
20+ 'M' ,
21+ 'N' ,
22+ 'O' ,
23+ 'P' ,
24+ 'Q' ,
25+ 'R' ,
26+ 'S' ,
27+ 'T' ,
28+ 'U' ,
29+ 'V' ,
30+ 'W' ,
31+ 'X' ,
32+ 'Y' ,
33+ 'Z' ,
34+ 'a' ,
35+ 'b' ,
36+ 'c' ,
37+ 'd' ,
38+ 'e' ,
39+ 'f' ,
40+ 'g' ,
41+ 'h' ,
42+ 'i' ,
43+ 'j' ,
44+ 'k' ,
45+ 'l' ,
46+ 'm' ,
47+ 'n' ,
48+ 'o' ,
49+ 'p' ,
50+ 'q' ,
51+ 'r' ,
52+ 's' ,
53+ 't' ,
54+ 'u' ,
55+ 'v' ,
56+ 'w' ,
57+ 'x' ,
58+ 'y' ,
59+ 'z' ,
60+ 0 ,
61+ 1 ,
62+ 2 ,
63+ 3 ,
64+ 4 ,
65+ 5 ,
66+ 6 ,
67+ 7 ,
68+ 8 ,
69+ 9 ,
70+ ] ;
71+ function getCaptcha ( ) {
72+ for ( let i = 0 ; i < 6 ; i ++ ) {
73+ let randomCharacter =
74+ characters [ Math . floor ( Math . random ( ) * characters . length ) ] ;
75+ console . log ( randomCharacter ) ;
76+ captcha . innerText += ` ${ randomCharacter } ` ;
77+ //passing 6 random characters
78+ }
79+ }
80+ getCaptcha ( ) ;
81+
82+ reloadbtn . addEventListener ( 'click' , ( ) => {
83+ removeInput ( ) ;
84+ getCaptcha ( ) ;
85+ } ) ;
86+
87+ verifyBtn . addEventListener ( 'click' , ( e ) => {
88+ e . preventDefault ( ) ;
89+ responseTxt . style . display = 'block' ;
90+
91+ let inputVal = inputText . value . split ( '' ) . join ( ' ' ) ;
92+ if ( inputVal == captcha . innerText ) {
93+ responseTxt . style . color = '#85C88A' ;
94+ responseTxt . innerText = "Nice! You don't appear to be a robot." ;
95+ setTimeout ( ( ) => {
96+ removeInput ( ) ;
97+ getCaptcha ( ) ;
98+ } , 2000 ) ;
99+ } else {
100+ responseTxt . style . color = '#ff0000' ;
101+ responseTxt . innerText = 'Captcha not matched. Please try again!' ;
102+ }
103+ } ) ;
104+
105+ function removeInput ( ) {
106+ inputText . value = '' ;
107+ captcha . innerText = '' ;
108+ responseTxt . style . display = 'none' ;
109+ }
Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ font-family : 'Poppins' , sans-serif;
6+ }
7+
8+ body {
9+ display : flex;
10+ align-items : center;
11+ justify-content : center;
12+ min-height : 100vh ;
13+ background : # 19172e ;
14+ }
15+ .cover {
16+ max-width : 485px ;
17+ width : 100% ;
18+ background : # fff ;
19+ padding : 22px 30px 40px ;
20+ border-radius : 10px ;
21+ }
22+
23+ .cover header {
24+ color : # e45826 ;
25+ font-size : 30px ;
26+ font-weight : bold;
27+ text-align : center;
28+ }
29+ .cover .captcha-box {
30+ display : flex;
31+ height : 65px ;
32+ margin : 30px 0 20px ;
33+ align-items : center;
34+ justify-content : space-between;
35+ }
36+ .captcha-box .captcha-img {
37+ height : 100% ;
38+ width : 345px ;
39+ user-select : none;
40+ background : # 000 ;
41+ border-radius : 5px ;
42+ position : relative;
43+ }
44+ .captcha-img img {
45+ width : 100% ;
46+ height : 100% ;
47+ object-fit : cover;
48+ border-radius : 5px ;
49+ opacity : 0.95 ;
50+ }
51+ .captcha-img .captcha {
52+ position : absolute;
53+ left : 50% ;
54+ top : 50% ;
55+ width : 100% ;
56+ color : # ececec ;
57+ font-size : 35px ;
58+ font-style : italic;
59+ text-align : center;
60+ letter-spacing : 10px ;
61+ transform : translate (-50% , -50% );
62+ }
63+ .cover button {
64+ outline : none;
65+ border : none;
66+ color : # fff ;
67+ cursor : pointer;
68+ background : # e45826 ;
69+ border-radius : 5px ;
70+ }
71+
72+ .captcha-box .reload {
73+ width : 75px ;
74+ height : 100% ;
75+ font-size : 25px ;
76+ }
77+
78+ .cover .input-text {
79+ height : 60px ;
80+ width : 100% ;
81+ position : relative;
82+ }
83+ .input-text input {
84+ width : 100% ;
85+ height : 100% ;
86+ outline : none;
87+ padding-left : 20px ;
88+ font-size : 20px ;
89+ border-radius : 5px ;
90+ border : 1px solid # bfbfbf ;
91+ }
92+ .input-text input {
93+ padding-left : 19px ;
94+ border : 2px solid # e45826 ;
95+ }
96+
97+ .input-text .verify {
98+ position : absolute;
99+ right : 7px ;
100+ top : 50% ;
101+ font-size : 17px ;
102+ height : 45px ;
103+ padding : 0 20px ;
104+
105+ transform : translateY (-50% );
106+ }
107+
108+ .cover .result {
109+ display : none;
110+ font-size : 18px ;
111+ text-align : center;
112+ margin : 20px 0 -5px ;
113+ }
Original file line number Diff line number Diff line change @@ -577,7 +577,13 @@ <h4>CRUD Application</h4>
577577 < h4 > Text-To-Speech</ h4 >
578578 </ a >
579579 </ div >
580-
580+ < div class ="item ">
581+ < a target ="_blank " href ="97-Captcha Generator/index.html ">
582+ < img src ="30DaysOfJavaScript/assets/97.png " alt ="Captcha Generator " />
583+ < h4 > Captcha Generator</ h4 >
584+ </ a >
585+ </ div >
586+
581587 </ div >
582588 <!-- Main Section End -->
583589
You can’t perform that action at this time.
0 commit comments