summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-04-22 13:33:09 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-04-22 13:33:09 +0200
commitdec1359e90e847c90629e43ef3744539e8fb41c8 (patch)
treeda2d2ea07745c4eff127e4c62113e5f197dbc8c1 /src
parentd6e6f65a1cf8723a398689b549dd970121655053 (diff)
downloadaCms-dec1359e90e847c90629e43ef3744539e8fb41c8.tar.gz
aCms-dec1359e90e847c90629e43ef3744539e8fb41c8.tar.bz2
added base64 coding/decoding libary
showing captcha in login page (not verifying yet)
Diffstat (limited to 'src')
-rw-r--r--src/base64.cpp0
-rw-r--r--src/base64.hpp4
-rw-r--r--src/user.cpp34
-rw-r--r--src/user_content.hpp3
4 files changed, 39 insertions, 2 deletions
diff --git a/src/base64.cpp b/src/base64.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/base64.cpp
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 <cppdb/frontend.h>
#include <cppcms/session_interface.h>
#include <booster/posix_time.h>
+#include <b64/encode.h>
+#include <sstream>
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 );