Generating Registration Image on FLY
This article focus on generating image on fly in asp.net. This is very basic functionality which you find on almost all the website which require registration of user. Example: Yahoo Registration require to type you secret string before you can successfully login, this feature has no. of reasons and i am not going into detail of why we want rather i am explaining here how we can. Look for Screenshot for better idea.
|
For demo purpose i am generating image on button click. But generally you require to generate image on page load event of registration form.
|
Ok back on coding.
Step1: Create a new web application
Step2: Open Code Behind Form of web application you have created.
Step3: Add Namespace for drawing Image.
using System.Drawing;
using System.Drawing.Imaging;
Step4: Write Code for Generating Random Registration String (Here: Generating Random string of 10 in length).
|
// Generate a random password with the specified length. The password will only
// contain digits and letters (either lowercase or uppercase)
public static string GetRandomPassword(int length)
{
Random rand = new Random();
System.Text.StringBuilder password = new System.Text.StringBuilder(length);
for (int i = 1; i <= length; i++)
{
int charIndex;
// allow only digits and letters
do
{
charIndex = rand.Next(48, 123);
} while (!((charIndex >= 48 && charIndex <= 57) ||
(charIndex >= 65 && charIndex <= 90) || (charIndex >= 97 && charIndex <= 122
|
© 2008 dotnetwatch.com -- Privacy policy
Website Design & Internet Marketing by Shivam