i want to receve a get request from user and respond a picture with number in it to that user. and then receve number in the picture from user and if the number true send back some data to that user.
and i dont want to use CAPCHA services.
how can i handle request and respond with expressjs?
Here would be the basic steps:
- Install express-session so you can have server-state per client
- Client sends GET request to get image
- Generate random number
- Store random number and current server time/date in client session object
- Create or select the appropriate image that contains the previously selected random number
- Send the image as the response to the initial GET request
- Client sends a POST request with the number that the user typed probably as a form POST.
- Server gets the POST request data out of the body and compares the submitted number to the number in the
req.sessionobject and also checks to see if the current server time is close enough to the time/date in the session so the previous data has not yet expired. If both tests pass, then client has appropriately submitted the number in the picture and you can set a flag in
req.sessionthat indicates this client has passed. If both tests don’t pass, then you clear the number and date/time in
req.sessionand send a response that indicates failure.
- Future requests from this client can check the session object to see if this client has recently passed the image number validation or not. You may or may not want to set an expiration on the image validation.