[Cppcms-users] cppdb , weird data corruption when using cppms::util::md5hex in cppdb::statement:
Brought to you by:
artyom-beilis
|
From: SIMON A. <All...@su...> - 2012-11-14 10:49:21
|
Hello
I've met a quiet weird problem
When trying to execute the code below, that simply insert some data in a Sqlite3 database, the data inserted are corrupted
however if I put first the result of md5hex in a const string and then bind with this string, the data corruption does not appear
here is the code
----------------------------
#include <cppdb/frontend.h>
#include <cppcms/util.h>
#include <iostream>
#include <booster/posix_time.h>
int main()
{
cppdb::session sql("sqlite3:db=toto.db");
cppdb::statement addUser = sql.prepare(
"INSERT INTO users(username, password, email, since)"
"VALUES(?,?,?,?)"
);
const std::string login = "bbbb";
std::string pass = "toto";
std::string email = "023...@su...";
addUser.bind(login);
addUser.bind(
cppcms::util::md5hex(pass)
);
std::cout << cppcms::util::md5hex(pass) << std::endl;
addUser.bind(email);
addUser.bind(
booster::ptime::now().get_seconds()
);
addUser.exec();
addUser.reset();
}
------------------------------
here is the dump of the database
CREATE TABLE users (
"id" integer primary key autoincrement not null ,
"username" text not null unique, -- his nickname
"email" text not null unique, -- his email address
"image" text not null default "unknown" , -- his personnal image
"password" text not null, -- his password hashed
"since" integer not null, -- his registering date
"homepage" text default "", -- his personnal webpage/website
"description" text default "" -- his self-written description
);
INSERT INTO "users" VALUES(1,'toto','12...@su...','unknown','23...@su...?ab494817525c6',1352888183,'','');
As you can see the password's hash is mixed with the email field, by doing the test several time, sometimes the hash is mixed with other data (the username for example)
I've compiled with this command
clang++ main.cpp -lcppdb -lcppcms -lbooster
Thanks for your help
Regards,
Allan SIMON
Tatoeba Administrator (Sysko)
|