How to generate a verification code(mixed of char and int)?

Posted by Amitabkabir under ASP.NET on 10/22/2008 | Views : 2713 | Status : [Member] | Replies : 1
Maximum form registration there may be need to generate a verification code to verify the form entry.Please show me the code(C#.NET) and where to use that code in details.


Posted by: Majith on: 10/23/2008 [Member] Starter

hi amit,

use the below code for generating char,int (mixed) and you can convert into image format.

private string genrandom(int count)


string var ="A-Z,0-9";
// for the above code use A to z characters and 0 to 9 nos

string[] verifycode = var.Split(',');

int t=-1;
// temp varaiable
string finalcode =string.Empty;

Random rand = new Random();

for (int i = 0; i < count; i++)
if t!= -1)
rand = new Random(i * t* ((int)DateTime.Now.Ticks));
int t1 = rand.Next(36);
if t!= -1 && temp == 1
return genrandom(count);
t= t1;
finalcode += verifycode [t1];
return finalcode;

Amitabkabir, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response