X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fcaptcha%2Fsimplecaptcha.cpp;h=512774e301562ebc1df32b77a2f7eebde3869891;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=c030bca0a061c4f472d7b1a953c788e11191a723;hpb=d8f51eac91f86a1e00a05a5058a8fa9eb8732464;p=fms.git diff --git a/src/freenet/captcha/simplecaptcha.cpp b/src/freenet/captcha/simplecaptcha.cpp index c030bca..512774e 100644 --- a/src/freenet/captcha/simplecaptcha.cpp +++ b/src/freenet/captcha/simplecaptcha.cpp @@ -3,6 +3,10 @@ #include "../../../include/freenet/captcha/easybmp/EasyBMP_Font.h" #include "../../../include/freenet/captcha/easybmp/EasyBMP_Geometry.h" +#include + +#include + #ifdef XMEM #include #endif @@ -10,11 +14,13 @@ void SimpleCaptcha::Generate() { BMP bmp; - int bmpwidth=100; + int bmpwidth=110; int bmpheight=50; + RGBApixel lettercols[5]; std::string puzzlestring; - std::string tempfilename=GenerateRandomString(10); - tempfilename+=".bmp"; + std::string tempfilename=""; + + tempfilename=Poco::TemporaryFile::tempName(); puzzlestring=GenerateRandomString(5); m_solution.clear(); @@ -23,7 +29,7 @@ void SimpleCaptcha::Generate() bmp.SetSize(bmpwidth,bmpheight); // first draw some random lines around the bitmap - int numlines=(rand()%20)+10; + int numlines=(rand()%10)+10; for(int i=0; iskew; xx--) + { + pixel=bmp.GetPixel(xx-skew,yy); + bmp.SetPixel(xx,yy,pixel); + } + } + for(xx=bmpwidth+skew; xx 255 ? tempred=255 : false; + tempgreen < 0 ? tempgreen=0 : false; + tempgreen > 255 ? tempgreen=255 : false; + tempblue < 0 ? tempblue=0 : false; + tempblue > 255 ? tempblue=255 : false; + + pixel.Red=tempred; + pixel.Green=tempgreen; + pixel.Blue=tempblue; + + bmp.SetPixel(xx,yy,pixel); + } } bmp.WriteToFile(tempfilename.c_str()); @@ -56,7 +149,8 @@ void SimpleCaptcha::Generate() const std::string SimpleCaptcha::GenerateRandomString(const int len) { - static std::string chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + // no l,1 O,0 because they look too much alike + static std::string chars="abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789"; std::string temp=""; for(int i=0; i