B4J Library jEasyCaptcha - Setup your own Captcha Server

jEasyCaptcha is a simple method can help setup your own captcha server.

getcaptcha (1).png
getcaptcha (2).png


Captcha Server:
Sub Class_Globals
    Dim captcha As jEasyCaptcha
End Sub

Public Sub Initialize
    captcha.Initialize(320,90, 5)
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    resp.ContentType = "image/gif"
    resp.setHeader("Pragma", "No-cache")
    resp.setHeader("Cache-Control", "no-cache")
    
    req.GetSession.SetAttribute("captcha",captcha.toString)
    captcha.setFont("Arial", 12)
    captcha.WriteOut(resp.OutputStream)
    
End Sub

Verify Captcha:
Sub Class_Globals
    
End Sub

Public Sub Initialize
    
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    
    Dim verCode As String = req.GetParameter("code")
    Dim sessionCode As String = req.getSession().getAttribute("captcha")
    
    Log("sessionCode=" & sessionCode)
    
    Dim json As String
    
    If (verCode = Null) Or (sessionCode.Contains(verCode) = False) Then
        json = $"{"result":"false"}"$       
    Else
        json = $"{"result":"true"}"$
    End If
    
    Log(json)
End Sub
 

Attachments

  • jEasyCaptcha.zip
    29.5 KB · Views: 39
  • Example.zip
    1.9 KB · Views: 38
Top