-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.cpp
More file actions
60 lines (59 loc) · 1.71 KB
/
auth.cpp
File metadata and controls
60 lines (59 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @file auth.cpp
* @brief Authentication implementation
* @author mnxoid
*
* Copyright 2014 by mnxoid,
*
* This software is the confidential and proprietary information
* of mnxoid ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with mnxoid.
**/
#define AUTH_CPP
#include "auth.h"
#include <QString>
#include <QDebug>
#include "packet.h"
extern int session; //!< Current SESSION_ID
/**
* @brief The authentication function
* @param [in] login - User name
* @param [in] pwd - User password
*
* @return Access Privilege level
* @see Access
*
**/
Access Check(QString login, QString pwd)
{
char *data = (char*)malloc(2*sizeof(int)+login.length()+pwd.length());
*((int*)data) = login.length();
*((int*)data+1) = pwd.length();
strncpy(data+2*sizeof(int),login.toStdString().c_str(),login.length());
strncpy(data+2*sizeof(int)+login.length(),pwd.toStdString().c_str(),pwd.length());
Packet p(AUTH,session,2*sizeof(int)+login.length()+pwd.length(),data);
// Packet resp = p.send("127.0.0.1",1337);
// if (resp.getRequestID()==RESP_OK)
// {
// session = resp.getSessionID();
// data = resp.rawData();
// Access a = *((Access*)data);
// QList
// return a;
free(data);
if (login == "Admin") {
return ADMIN;
} else if (login == "ExUser") {
return EXUSER;
} else if (login == "User") {
return USER;
} else {
return DENIED;
}
// } else {
// qDebug() << "Error: Bad request";
// }
}
#undef AUTH_CPP