Randomly Generated Verification COde...

vishalrane 1 Tallied Votes 789 Views Share
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckCode.aspx.cs" Inherits="CheckCode" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Verification code to prevent auto signup in ASP.NET 2.0</title>
   <style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	color: #0000FF;
}
a:visited {
	color: #0000FF;
}
a:hover {
	color: #0000FF;
	text-decoration: none;
}
a:active {
	color: #0000FF;
	}
.basix {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.header1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	font-weight: bold;
	color: #006699;
}
.lgHeader1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	font-weight: bold;
	color: #0066CC;
	background-color: #CEE9FF;
}
-->
</style> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        &nbsp;</div>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </form>
</body>
</html>

Dani AI

Generated

Short, practical pattern to add a verification code to the ASP.NET/C# page started: generate a cryptographically strong code, store it server-side with an expiry, render it as an image from a small handler, and verify on postback. That keeps logic out of HTML/CSS (so 's layout tip helps placement but does not replace server-side checks).

Example: secure token generator (use this to create and store the expected code in Session).

private string GenerateCaptchaCode(int length = 6)
{
    const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
    var bytes = new byte[length];
    using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())
    {
        rng.GetBytes(bytes);
    }
    var result = new char[length];
    for (int i = 0; i < length; i++)
        result[i] = chars[bytes[i] % chars.Length];
    return new string(result);
}

Render the image from an .ashx or dedicated endpoint (minimal example: draw the stored Session code, add simple noise, write PNG to Response). Keep the image handler code small and stateless except for reading the Session value.

Validate on postback by comparing the user input to the Session value (case-insensitive), then remove the Session entry and check a timestamp to expire old tokens. Example checks: compare with StringComparison.OrdinalIgnoreCase, clear Session on success, and reject if older than a few minutes.

Notes and cautions: avoid System.Random for token generation; use a crypto RNG. System.Drawing/GDI+ is fine for classic ASP.NET 2.0 but can be heavy on very high traffic—consider an external CAPTCHA service or an audio alternative for accessibility. Also add simple rate-limiting and invalidate the code on first use to prevent replay.

vishalrane 0 Junior Poster in Training

Its not vb.net but asp.net using C#....
bymistakely got posted in vb.net forum....
Sory....

yusuf_3 0 Newbie Poster

For next time give

margin:0px auto;

for body tag....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.