Creating Captcha Code with JavaScript

Introduction

 
Here I create a Captcha Code with JavaScript.
 
Step 1
 
In the (.aspx) page we write the following Code:
  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head id="Head1" runat="server">  
  5.     <title></title>  
  6.      <script language="javascript">  
  7.          var a = 49, b = 65;  
  8.          var c = 100;  
  9.          var d = 70;  
  10.          function show() {  
  11.              if (a == 57) {  
  12.                  a = 49;  
  13.              }  
  14.              var main = document.getElementById('txt1');  
  15.              var a1 = String.fromCharCode(a);  
  16.              var b1 = String.fromCharCode(b);  
  17.              var c1 = String.fromCharCode(c);  
  18.              var d1 = String.fromCharCode(d);  
  19.              main.value = a1 + b1 + c1 + d1;  
  20.              a = a + 1;  
  21.              b = b + 1;  
  22.              c = c + 1;  
  23.              d = d + 1;  
  24.          }  
  25.   </script>  
  26.     <style type="text/css">  
  27.         #form1  
  28.         {  
  29.             height: 95px;  
  30.         }  
  31.     </style>  
  32. </head>  
  33. <body>  
  34.     <form id="form1" runat="server">  
  35.     <div>  
  36.     <input type="text" id="txt1" runat="server"  
  37.             style="border-style: none; border-color: inherit; border-width: medium; background-color:black; color:red; font-family: 'Curlz MT'; font-size: x-large; font-weight: bold; font-variant: normal; letter-spacing: 10pt; width: 120px; background-image: url('glitter_background_b4.gif');"  
  38.             value="5AbD" />  
  39.   <input type="button" onclick="show()" value="Change"  />  
  40.         </div>  
  41.     <asp:TextBox ID="txtverification" runat="server"></asp:TextBox>  
  42.       
  43.     <asp:Button ID="Button1" runat="server" Text="Verification"  
  44.         onclick="Button1_Click" />  
  45.           
  46.     <asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>  
  47.     </form>  
  48. </body>  
  49. </html> 
Step 2
 
In the (.cs) page I write the following code for verification:
  1. protected void Button1_Click(object sender, EventArgs e)  
  2. {  
  3.     if (txtverification.Text == txt1.Value)  
  4.     {  
  5.         lblmsg.Text = "Successful";  
  6.     }  
  7.     else  
  8.     {  
  9.         lblmsg.Text = "Failure";  
  10.     }