From dec1359e90e847c90629e43ef3744539e8fb41c8 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 22 Apr 2015 13:33:09 +0200 Subject: added base64 coding/decoding libary showing captcha in login page (not verifying yet) --- src/base64.cpp | 0 src/base64.hpp | 4 ++++ src/user.cpp | 34 +++++++++++++++++++++++++++++++++- src/user_content.hpp | 3 ++- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/base64.cpp create mode 100644 src/base64.hpp (limited to 'src') diff --git a/src/base64.cpp b/src/base64.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/base64.hpp b/src/base64.hpp new file mode 100644 index 0000000..1c55655 --- /dev/null +++ b/src/base64.hpp @@ -0,0 +1,4 @@ +#ifndef BASE64_HPP +#define BASE64_HPP + +#endif diff --git a/src/user.cpp b/src/user.cpp index 8f18706..d94cd6f 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace apps { @@ -81,10 +83,40 @@ bool user::check_login( std::string user, std::string password ) return true; } +#define GIFSIZE 17646 +extern "C" { + const int gifsize = GIFSIZE; + void captcha( unsigned char im[70*200], unsigned char l[6]); + void makegif(unsigned char im[70*200], unsigned char gif[gifsize]); +} + void user::ini( content::user &c ) { master::ini( c ); - c.captcha = ">> CAPTCHA <<"; + unsigned char l[6]; + unsigned char *im = new unsigned char[70*200]; + unsigned char *gif = new unsigned char[gifsize]; + + captcha( im, l ); + c.captcha_text = std::string( (char *)l ); + + std::ostringstream raws( std::stringstream::out | std::stringstream::binary ); + makegif( im, gif ); + raws.write( (char *)gif, gifsize ); + std::string raw = raws.str( ); + + std::istringstream in( std::ios_base::in | std::ios_base::binary ); + in.str( raw ); + + base64::encoder E; + std::string base_s; + base_s.reserve( 3 * gifsize ); + std::ostringstream base( base_s, std::stringstream::out | std::stringstream::binary ); + E.encode( in, base ); + c.captcha_base64 = base.str( ); + + delete gif; + delete im; } } // namespace apps diff --git a/src/user_content.hpp b/src/user_content.hpp index 887c61a..857a15c 100644 --- a/src/user_content.hpp +++ b/src/user_content.hpp @@ -22,7 +22,8 @@ struct login_form : public cppcms::form { struct user : public master { login_form login; - std::string captcha; + std::string captcha_text; + std::string captcha_base64; public: user( apps::strusCms &cms ); -- cgit v1.2.3-54-g00ecf