Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[BETA DEMO] RB Math CAPTCHA widget

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 729

PostPosted: Feb 15th, 2009, 3:57am    Post subject: [BETA DEMO] RB Math CAPTCHA widget Reply with quote

Code:
[Test Captcha]
cls
print "Please answer a simple math problem to continue."
[Repeat Captcha]
run "MathCaptcha", #captcha
#captcha Difficulty(1,5)
#captcha SetFocus()
render #captcha
button #b, "Submit", [Check Captcha]
wait
[Check Captcha]
print
if #captcha IsValid() then
    cls
    print "Correct."
else
    cls
    print "Incorrect. Try again."
    goto [Repeat Captcha]
end if
end


Code:
' Math CAPTCHA
' By Brent D. Thorn
' Created 2/2009
' PUBLIC DOMAIN

Global m.answer
Global #answer

Function Difficulty(low, high)
    low = Min(Max(low, 1), 5)
    high = Min(Max(high, 1), 5)
    n = Abs(high - low) + 1
    n = Int(n * Rnd(0) + low)
    Select Case n
    Case 1 ' a + b
        a = Int(5 * Rnd(0) + 1)
        b = Int(5 * Rnd(0))
        m.answer = a + b
        Print a;" + ";b;" = ";
    Case 2 ' a + b + c
        a = Int(10 * Rnd(0))
        b = Int(10 * Rnd(0))
        c = Int(10 * Rnd(0))
        m.answer = a + b + c
        Print a;" + ";b;" + ";c;" = ";
    Case 3 ' aa + b
        a = Int(90 * Rnd(0) + 10)
        c = Int(10 * Rnd(0))
        m.answer = a + b
        Print a;" + ";b;" = ";
    Case 4 ' a * b
        a = Int(10 * Rnd(0) + 1)
        b = Int(10 * Rnd(0) + 1)
        m.answer = a * b
        HTML a;" × ";b;" = "
    Case 4 ' a * b + c
        a = Int(10 * Rnd(0))
        b = Int(10 * Rnd(0))
        c = Int(10 * Rnd(0))
        m.answer = a * b + c
        HTML a;" × ";b;" + ";c;" = "
    Case 5 ' a + b * c
        a = Int(10 * Rnd(0))
        b = Int(10 * Rnd(0))
        c = Int(10 * Rnd(0))
        m.answer = a + b * c
        HTML a;" + ";b;" × ";c;" = "
    End Select

    TextBox #answer, ""
End Function

Function IsValid()
    IsValid = (#answer Value() = m.answer)
End Function

Function SetFocus()
    #answer SetFocus()
End Function

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming All times are GMT
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group