Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit 6eb6bc5

Browse files
authored
add login and some more
Added login Added token generator Added useless check token function, as it doesn't work for now. Added setup table bans
1 parent d770bc0 commit 6eb6bc5

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

framework.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function setup(){
7575
$setup = $db->prepare("CREATE TABLE `".$dbname."`.`token` ( `uid` INT(10) NOT NULL , `token` VARCHAR(64) NOT NULL ) ENGINE = MyISAM;");
7676
$setup->execute();
7777
if(!$setup->error){
78-
echo "<br>tokens created<br>Finished!";
78+
echo "<br>tokens created";
79+
$setup = $db->prepare("CREATE TABLE `".$dbname."`.`bans` ( `uid` INT(10) NOT NULL ) ENGINE = MyISAM;");
7980
return 1;
8081
} else {
8182
echo "epic fail";
@@ -101,7 +102,46 @@ function clogin($username, $password){
101102
}
102103

103104
function login($username, $password){
105+
global $usecookies;
106+
global $db;
107+
$login = $db->prepare("SELECT * FROM users WHERE username = ?");
108+
$login->bind_param("s", $username);
109+
$login->execute();
110+
if(!mysqli_num_rows){
111+
return "noaccount";
112+
} else {
113+
$result = $login->get_result();
114+
$row = $result->fetch_assoc();
115+
if($row["password"] != password_hash($password, PASSWORD_DEFAULT){
116+
return "invalid password";
117+
} else {
118+
$token = "DO NOT SHARE YOUR COOKIES TO ANYBODY. value: ".bin2hex(openssl_random_pseudo_bytes(64));."";
119+
$login = $db->prepare("INSERT INTO token (uid, token) VALUES (?, ?)");
120+
$login->bind_param("is", $row["id"], $token);
121+
$login->execute();
122+
if(!$login->error){
123+
if($usecookies){
124+
global $_COOKIE;
125+
setcookie("DO NOT GIVE YOUR COOKIES TO ANYBODY", "DO NOT GIVE YOUR COOKIES TO ANYBODY", time()+99999);
126+
setcookie("token", $token, time()+99999);
127+
setcookie("id", $row["id"], time()+99999);
128+
setcookie("username" $row["username"], time()+99999);
129+
} else {
130+
global $_SESSION;
131+
// I would put a don't give your cookies to anybody here, but guess what? You can't read PHP Session IDs! :DDD But seriously. don't give your cookies to anybody.
132+
$_SESSION["token"] = $token;
133+
$_SESSION["id"] = $row["id"];
134+
$_SESSION["username"] = $row["username"];
135+
}
136+
} else {
137+
return $login->error();
138+
}
139+
}
140+
}
141+
}
142+
143+
function checktoken($username, $token){
104144
return "not implemented";
105145
}
106-
//checkver("b1019");
146+
//checkver("b1020");
107147
?>

0 commit comments

Comments
 (0)