-
Notifications
You must be signed in to change notification settings - Fork 0
/
accountcreation.php
170 lines (127 loc) · 3.85 KB
/
accountcreation.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
$serverconfigs = parse_ini_file("config.ini",false);
$servername = $serverconfigs['servername'];
$db_username = $serverconfigs['username'];
$db_password = $serverconfigs['password'];
$db_name = $serverconfigs['databasename'];
$betakeyneeded = $serverconfigs['isbetakeyneeded'];
global $servername;
global $db_username;
global $db_password;
global $db_name;
global $betakeyneeded;
if (array_key_exists("username", $_POST) && array_key_exists("password", $_POST) && array_key_exists("betakey",$_POST)) {
createAccount($_POST["username"], ($_POST["password"]),$_POST["betakey"]);
}
function createAccount($username,$password,$betakey){
$up_betakey = strtoupper($betakey);
$up_username = strtoupper($username);
$up_password = strtoupper($password);
$isBetaKeyused = checkbetakey($up_betakey);
if($GLOBALS['betakeyneeded'] == 1){
if($up_betakey == ""){
echo "Without BetaKey no Accountcreation!";
return;
}
if($isBetaKeyused == "1"){
echo "BetaKey is used";
return;
}
if($isBetaKeyused == "-1"){
echo "BetaKey not found!";
return;
}
}
$accountExist = checkifAccountexist($up_username);
if($accountExist == "1"){
echo "Account already exists";
return;
}
// Create connection
$conn = new mysqli($GLOBALS["servername"], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connection failed";
}
$passwordbuilder = $up_username .":".$up_password;
$hashed_pw = sha1($passwordbuilder);
//echo $hashed_pw;
$final_pw = strtoupper ($hashed_pw);
// prepare and bind
$stmt = $conn->prepare("INSERT INTO account (username, sha_pass_hash) VALUES (?,?)");
$stmt->bind_param("ss",$user_name, $user_password);
// set parameters and execute
$user_name = $up_username;
$user_password = $final_pw;
$stmt->execute();
betaKeyUsed($up_betakey);
$stmt->close();
$conn->close();
echo "Accountcreation successfull!";
return;
}
function betaKeyUsed($betakey){
$up_betakey = strtoupper($betakey);
$conn = new mysqli($GLOBALS["servername"], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connection failed";
}
$stmt = $conn->prepare("Update betakey set `active` = 1 where `betakeynr` = ?");
$stmt->bind_param("s",$db_betakeynr);
// set parameters and execute
$db_betakeynr = $up_betakey;
$stmt->execute();
$stmt->close();
$conn->close();
}
function checkifAccountexist($username){
$conn = new mysqli($GLOBALS["servername"], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username FROM account";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if($row["username"] == $username){
return "1";
}
}
return "0";
$conn->close();
}
}
function checkbetakey($betakey){
$up_betakey = strtoupper($betakey);
$server = $GLOBALS['servername'];
$dbuser = $GLOBALS['db_username'];
$dbpass = $GLOBALS['db_password'];
$dbschema = $GLOBALS['db_name'];
$conn = new mysqli($server, $dbuser,$dbpass, $dbschema);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, betakeynr, active FROM betakey";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if(strtoupper($row["betakeynr"]) == $up_betakey){
//echo strtoupper($row["betakeynr"]);
$conn->close();
return $row["active"];
}
}
} else {
$conn->close();
return "-1";
}
$conn->close();
}
?>