Image verification

M

Mike P

I am trying to generate an image on my login screen that the user must
enter the characters of in order to login successfully. I have managed
to find a method that returns a bitmap, but I am not sure how to render
it to the page alongside the rest of the login page.

Bitmap bmp = iv.generateImage(sTxt);


Response.ContentType = "image/gif";
bmp.Save(Response.OutputStream, ImageFormat.Gif);

bmp.Dispose();

I guess I will need to switch Response.ContentType to also show the rest
of the page. What do I need to do to show both my image and the rest of
the page on screen?
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

What you need to do is have an IMG tag in the login page that will
reference the page/URL that will dynamically generate the image. You will
have to pass along any information in the URL that the page needs to
generate the image.
 
L

Lasse Vågsæther Karlsen

Mike said:
I am trying to generate an image on my login screen that the user must
enter the characters of in order to login successfully. I have managed
to find a method that returns a bitmap, but I am not sure how to render
it to the page alongside the rest of the login page.

Bitmap bmp = iv.generateImage(sTxt);


Response.ContentType = "image/gif";
bmp.Save(Response.OutputStream, ImageFormat.Gif);

bmp.Dispose();

I guess I will need to switch Response.ContentType to also show the rest
of the page. What do I need to do to show both my image and the rest of
the page on screen?

This piece of "technology" is called a CAPTHCA, so google for some examples.
 
M

Mike P

Nicholas,

If the image is being created on a separate page and then viewed through
an Image control on the Login page, how do I get at the string that is
created on the Image page so that I can verify that what the user types
in matches the string?
 
J

Jesse Houwing

Hello Mike,
Nicholas,

If the image is being created on a separate page and then viewed
through an Image control on the Login page, how do I get at the string
that is created on the Image page so that I can verify that what the
user types in matches the string?

You can store it in the Session or the Viewstate.
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

Well, the login page is going to place the IMG tag in the page, right?
And you are using Session State or something in the query string to indicate
what the string used in the image should be. The login page should be
generating this string, or the page generating the image should be placing
it in session state (I don't like this, because you might have multiple
requests in the same session hitting that variable, and it could cause
issues).

Either way, the login page is aware of the string already. I recommend
that the login page generates the string, and then passes it to the page
generating the image, using some sort of encryption key (I like generating a
hash using the ASP.NET session id and then using that as an encyrption key
across the session).
 
O

Oddball

Cheers!

*** Sent via Developersdexhttp://www.developersdex.com***

The way I solved this was I used the Cache, stored my string in there
with a short expiery and a GUID as a key. I passed the Guid to the
handler to genarate the CAPTCHA image - the handler then retrieved the
string from the Cache - minimal collision problems curtesy of Guid
immense phase space. Isn't there more chance of winning every lottery
on the planet or something?

Your login page would be responsible for removing the string from the
cache, but the cache will do it itself after... say... five, ten
minutes? Long enough for the turboest of R-Type 'tards to work out
what's going on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top