标题:随机生成验证码的一个演示升级版+++
取消只看楼主
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
结帖率:97.44%
已结贴  问题点数:20 回复次数:7 
随机生成验证码的一个演示升级版+++
上次做的是直接在form上画,运行速度有点慢,现在改成在内存上,速度就快多了,而且生成的验证码图片,用上次吹水佬的二极化代码无法彻底去噪

附上代码,有兴趣的可以提高一下二极化的代码算法。。。

程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\logondemo.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   10/23/22 09:00:05 PM
*
DEFINE CLASS form1 AS form


    DoCreate = .T.
    AutoCenter = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT label1 AS label WITH ;
        Caption = "用户名", ;
        Height = 16, ;
        Left = 110, ;
        Top = 30, ;
        Width = 38, ;
        Name = "Label1"


    ADD OBJECT text1 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 26, ;
        Width = 100, ;
        Name = "Text1"


    ADD OBJECT label2 AS label WITH ;
        Caption = "密  码", ;
        Height = 16, ;
        Left = 110, ;
        Top = 60, ;
        Width = 38, ;
        Name = "Label2"


    ADD OBJECT text2 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 56, ;
        Width = 100, ;
        PasswordChar = "*", ;
        Name = "Text2"


    ADD OBJECT label3 AS label WITH ;
        Caption = "验证码", ;
        Height = 16, ;
        Left = 110, ;
        Top = 90, ;
        Width = 38, ;
        Name = "Label3"


    ADD OBJECT text3 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 85, ;
        Width = 100, ;
        Name = "Text3"


    ADD OBJECT label4 AS label WITH ;
        AutoSize = .T., ;
        Caption = "点击显示验证码", ;
        Height = 16, ;
        Left = 100, ;
        Top = 128, ;
        Width = 86, ;
        Name = "Label4"


    ADD OBJECT image1 AS image WITH ;
        Height = 80, ;
        Left = 100, ;
        Top = 148, ;
        Width = 180, ;
        Name = "Image1"


    PROCEDURE image1.Init
        this.click
    ENDPROC


    PROCEDURE image1.Click
        thisform.Cls()
        RAND(-1)

        *****************************生成随机干扰码*************************************
        SET CLASSLIB TO HOME()+"FFC\_gdiplus.vcx"
        locolor=CREATEOBJECT("gpcolor",255,255,255,255)
        lobrush=CREATEOBJECT("gpsolidbrush",locolor)
        lographics=CREATEOBJECT("gpgraphics")
        lobitmap=CREATEOBJECT("gpbitmap",this.Width,this.height)
        lographics.createfromimage(lobitmap)
        lographics.fillrectangle(lobrush,0,0,this.width,this.height)
        FOR i=1 TO 150
            lncolor=INT(RAND()*1000000)
            nred=MOD(lncolor,0x100)
            ngreen=INT(MOD(lncolor,0x10000)/0x100)
            nblue=INT(lncolor/0x10000)
            locolor.set(nred,ngreen,nblue,255)
            lobrush.create(locolor)
            DO WHILE .t.
                nleft=INT(RAND()*200)
                ntop=INT(RAND()*100)
                IF nleft<this.Width-5 AND ntop<this.Height-5
                    EXIT
                ELSE
                    loop
                ENDIF
            ENDDO
            lographics.fillrectangle(lobrush,nleft,ntop,5,5)
        ENDFOR 
        *****************************生成随机干扰码*************************************

        *****************************生成随机验证码*************************************
        lpString = randomstr(4)
        FOR i=1 TO 4
            nleft=40*(i-1)
            ntop=10
            lopoint=CREATEOBJECT("gppoint",nleft,ntop)
            lofont=CREATEOBJECT("gpfont")
            lofont.create("arial",32,0,3)
            lncolor=INT(RAND()*1000000)
            nred=MOD(lncolor,0x100)
            ngreen=INT(MOD(lncolor,0x10000)/0x100)
            nblue=INT(lncolor/0x10000)
            locolor.set(nred,ngreen,nblue,255)
            lobrush=CREATEOBJECT("gpsolidbrush",locolor)
            lostringformat=CREATEOBJECT("gpstringformat")
            lographics.drawstringA(SUBSTR(lpstring,i,1),lofont,lopoint,lostringformat,lobrush)
        ENDFOR 
        *****************************生成随机验证码*************************************

        lobitmap.savetofile("background.jpg","image/jpeg","quality=100")
        this.picture="background.jpg"
        RELEASE ALL LIKE lo
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************


运行效果图如下:


二级化效果图如下:
搜索更多相关主题的帖子: Name Left Top INT WITH 
2022-10-23 21:17
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 4楼 foxfans
可以把这个整体搬迁到gitee或者蓝奏吗?那个github网页我永远都是打不开的。
2022-10-25 16:15
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 5楼 吹水佬
哈哈哈,好像是有点像色盲检测卡,好像给我指明了另一个拓展方向。。。
2022-10-25 16:16
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 6楼 easyppt
我上次那个贴子里有代码,所以这次没有把它发上来。

再发一下吧:
PARAMETERS tnlength   
LOCAL lcText, lcChar, x, n
lcText = ""
FOR n = 1 TO tnLength
    x = INT(RAND() * 36)
    lcChar = IIF(x < 10, TRANSFORM(x), CHR(x + 55))
    lcText = lcText + lcChar
ENDFOR
RETURN lcText
2022-10-25 16:18
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
好像可以对抗很多的文字识别软件,2345软件也识别不了!

2022-10-25 16:33
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 11楼 foxfans
thank you
2022-10-25 21:24
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 11楼 foxfans
win7系统下能正常工作吗?我怎么没法运行,没有报错,但是form没有
2022-10-29 15:42
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 6楼 easyppt
之前的代码只是大写字母和数字,现在上传有小写字母的。。。

程序代码:
PARAMETERS tnlength 
Rand(-1)
lctext = ''
i = 0
Do While i < tnlength
    kb = 48 + Rand() * 80
    If kb <= 57 And kb >= 48 Or kb <= 122 And kb >= 97 Or kb <= 90 And kb >= 65
        i = i + 1
        lctext = lctext + Chr(kb)
    Endif
Enddo
RETURN lctext
2022-10-29 15:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510425-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.257401 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved