summaryrefslogtreecommitdiff
path: root/src/client/Client.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-25 17:21:55 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-25 17:21:55 (GMT)
commit8b80942b16fd6292884fb3208bc52c29a25cfff8 (patch)
treefebd0a9004932d602f5de0be3ebf358a8611e1f2 /src/client/Client.cpp
parent3505bcc275dc2e276386e51b1dc13325d4eefa07 (diff)
downloadpowder-8b80942b16fd6292884fb3208bc52c29a25cfff8.zip
powder-8b80942b16fd6292884fb3208bc52c29a25cfff8.tar.gz
Login working, segfaults sometimes
Diffstat (limited to 'src/client/Client.cpp')
-rw-r--r--src/client/Client.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 0070e65..b6fe2a4 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -40,35 +40,31 @@ Client::~Client()
http_done();
}
-LoginStatus Client::Login(string username, string password)
+LoginStatus Client::Login(string username, string password, User & user)
{
lastError = "";
std::stringstream urlStream;
std::stringstream hashStream;
- unsigned char cHashData[16];
+ char passwordHash[33];
+ char totalHash[33];
- //Build hash of username + password
- struct md5_context md5;
- md5_init(&md5);
- md5_update(&md5, (unsigned char *)username.c_str(), username.length());
- md5_update(&md5, (unsigned char *)"-", 1);
- md5_update(&md5, (unsigned char *)password.c_str(), password.length());
- md5_final(cHashData, &md5);
- //Make sure hash is Hex
- //char * cHashHex = (char *)malloc(33);
- for(int i = 0; i < 16; i++)
- {
- hashStream << hexChars[cHashData[i]>>4] << hexChars[cHashData[i]&15];
- //cHashHex[i*2] = hex[cHashData[i]>>4];
- //cHashHex[i*2+1] = hex[cHashData[i]&15];
- }
- //cHashHex[32] = 0;
+ user.ID = 0;
+ user.Username = "";
+ user.SessionID = "";
+ user.SessionKey = "";
+
+ //Doop
+ md5_ascii(passwordHash, (const unsigned char *)password.c_str(), password.length());
+ passwordHash[32] = 0;
+ hashStream << username << "-" << passwordHash;
+ md5_ascii(totalHash, (const unsigned char *)(hashStream.str().c_str()), hashStream.str().length());
+ totalHash[32] = 0;
char * data;
int dataStatus, dataLength;
char * postNames[] = { "Username", "Hash", NULL };
- char * postDatas[] = { (char*)username.c_str(), (char*)hashStream.str().c_str() };
- int postLengths[] = { username.length(), hashStream.str().length() };
+ char * postDatas[] = { (char*)username.c_str(), totalHash };
+ int postLengths[] = { username.length(), 32 };
data = http_multipart_post("http://" SERVER "/Login.json", postNames, postDatas, postLengths, NULL, NULL, NULL, &dataStatus, &dataLength);
//data = http_auth_get("http://" SERVER "/Login.json", (char*)username.c_str(), (char*)password.c_str(), NULL, &dataStatus, &dataLength);
std::cout << data << std::endl;
@@ -84,6 +80,13 @@ LoginStatus Client::Login(string username, string password)
free(data);
if(tempStatus.Value() == 1)
{
+ json::Number userIDTemp = objDocument["UserID"];
+ json::String sessionIDTemp = objDocument["SessionID"];
+ json::String sessionKeyTemp = objDocument["SessionKey"];
+ user.Username = username;
+ user.ID = userIDTemp.Value();
+ user.SessionID = sessionIDTemp.Value();
+ user.SessionKey = sessionKeyTemp.Value();
return LoginOkay;
}
else
@@ -99,6 +102,10 @@ LoginStatus Client::Login(string username, string password)
return LoginError;
}
}
+ else
+ {
+ lastError = http_ret_text(dataStatus);
+ }
if(data)
{
free(data);