This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
92 lines (89 loc) · 2.95 KB
/
functions.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
<?php
//Functions
function cURL($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
function login($user, $password) {
$url = 'http://login.minecraft.net/?user='.$user.'&password='.$password.'&version=12';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
function randSess() {
$i = 0;
$session = "";
while ($i < 19) {
$session = $session.mt_rand(0, 9);
$i++;
}
return $session;
}
function storeSess($user, $sess) {
global $dbHost, $dbUser, $dbPass, $dbName, $dbTable;
$connection = mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
mysql_select_db($dbName) or die(mysql_error());
$test = mysql_fetch_array(mysql_query("SELECT EXISTS(SELECT 1 FROM ".$dbTable." WHERE name='".$user."')"));
if ($test[0] == 0) {
//Not in database, add
mysql_query("INSERT INTO ".$dbTable." (name, token, hash) VALUES('".mysql_real_escape_string($user)."', '".mysql_real_escape_string($sess)."', '0' ) ")
or die(mysql_error());
}
else {
//Already in database, update
mysql_query("UPDATE ".$dbTable." SET token='".mysql_real_escape_string($sess)."' WHERE name='".mysql_real_escape_string($user)."'")
or die(mysql_error());
}
}
function storeHash($user, $sess, $hash) {
global $dbHost, $dbUser, $dbPass, $dbName, $dbTable;
$connection = mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
mysql_select_db($dbName) or die(mysql_error());
$test = mysql_fetch_array(mysql_query("SELECT EXISTS(SELECT 1 FROM ".$dbTable." WHERE name='".$user."')"));
if ($test[0] == 0) {
//Not in database, ERROR!!!
return FALSE;
}
else {
//Already in database, check if session is OK then update
$result = mysql_query("SELECT * FROM ".$dbTable." WHERE name='".$user."'") or die(mysql_error());
$row = mysql_fetch_array($result);
if ($row['token'] == $sess) {
//Session matches, Store the $hash
mysql_query("UPDATE ".$dbTable." SET hash='".mysql_real_escape_string($hash)."' WHERE name='".mysql_real_escape_string($user)."'")
or die(mysql_error());
return TRUE;
}
else {
return FALSE;
}
}
}
function checkHash($user, $hash) {
global $dbHost, $dbUser, $dbPass, $dbName, $dbTable;
$connection = mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
mysql_select_db($dbName) or die(mysql_error());
$test = mysql_fetch_array(mysql_query("SELECT EXISTS(SELECT 1 FROM ".$dbTable." WHERE name='".$user."')"));
if ($test[0] == 0) {
//Not in database, ERROR!!!
return FALSE;
}
else {
//Already in database, check if hash matches
$result = mysql_query("SELECT * FROM ".$dbTable." WHERE name='".$user."'") or die(mysql_error());
$row = mysql_fetch_array($result);
if ($row['hash'] == $hash) {
//Hash matches
return TRUE;
}
else {
return FALSE;
}
}
}
?>