summaryrefslogtreecommitdiff
path: root/src/client
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
parent3505bcc275dc2e276386e51b1dc13325d4eefa07 (diff)
downloadpowder-8b80942b16fd6292884fb3208bc52c29a25cfff8.zip
powder-8b80942b16fd6292884fb3208bc52c29a25cfff8.tar.gz
Login working, segfaults sometimes
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.cpp47
-rw-r--r--src/client/Client.h3
-rw-r--r--src/client/MD5.cpp6
-rw-r--r--src/client/User.h29
4 files changed, 61 insertions, 24 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);
diff --git a/src/client/Client.h b/src/client/Client.h
index ef6a35e..15ab03a 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -9,6 +9,7 @@
#include "search/Thumbnail.h"
#include "search/Save.h"
#include "Singleton.h"
+#include "User.h"
enum LoginStatus
{
@@ -28,7 +29,7 @@ private:
public:
Client();
~Client();
- LoginStatus Login(string username, string password);
+ LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests();
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);
Thumbnail * GetPreview(int saveID, int saveDate);
diff --git a/src/client/MD5.cpp b/src/client/MD5.cpp
index 9cb398c..d921bfa 100644
--- a/src/client/MD5.cpp
+++ b/src/client/MD5.cpp
@@ -208,7 +208,7 @@ void md5_transform(unsigned buf[4], const unsigned char inraw[64])
buf[3] += d;
}
-static char hex[] = "0123456789abcdef";
+static char hexChars[] = "0123456789abcdef";
void md5_ascii(char *result, unsigned char const *buf, unsigned len)
{
struct md5_context md5;
@@ -224,8 +224,8 @@ void md5_ascii(char *result, unsigned char const *buf, unsigned len)
for (i=0; i<16; i++)
{
- result[i*2] = hex[(hash[i]>>4)&0xF];
- result[i*2+1] = hex[hash[i]&0x0F];
+ result[i*2] = hexChars[(hash[i]>>4)&0xF];
+ result[i*2+1] = hexChars[hash[i]&0x0F];
}
result[32] = 0;
}
diff --git a/src/client/User.h b/src/client/User.h
new file mode 100644
index 0000000..9dd231c
--- /dev/null
+++ b/src/client/User.h
@@ -0,0 +1,29 @@
+/*
+ * User.h
+ *
+ * Created on: Jan 25, 2012
+ * Author: Simon
+ */
+
+#ifndef USER_H_
+#define USER_H_
+
+#include <string>
+
+class User
+{
+public:
+ int ID;
+ std::string Username;
+ std::string SessionID;
+ std::string SessionKey;
+ User(int id, std::string username):
+ ID(id),
+ Username(username)
+ {
+
+ }
+};
+
+
+#endif /* USER_H_ */