Add files via upload

This commit is contained in:
NikolaiDerDeutsche
2023-12-03 00:06:49 +01:00
committed by GitHub
commit ebe454e805
6 changed files with 183 additions and 0 deletions

50
auth.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
include "connectionDB.php";
$message="";
if($_SERVER["REQUEST_METHOD"] === "POST") {
if(isset($_POST["username"]) && $_POST["password"]) {
try {
$get_user->execute(array($_POST["username"], $_POST["password"]));
$result = $get_user->fetch();
if($result) {
setcookie("user",crypt($_POST["password"],$_POST["username"]));
setcookie("userID",$result["id"]);
header("Location: /index.php");
}
else {
$add_user->execute(array($_POST["username"], $_POST["password"]));
}
} catch(Exception $e) {
if($e->getCode() == 23505) {
$message = "User alredy exists";
}
}
}
else {
$message = "Something missing!";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TinyTalkHub</title>
<link rel="stylesheet" href="css/global.css">
</head>
<body>
<form action="/auth.php" method="POST" class="form-auth-wrap">
<label>User login: </label>
<input name="username" placeholder="Type here..." /> <br/>
<label>User Password: </label>
<input name="password"placeholder="Type here..." /> </br>
<button>Submit</button>
<p> <?php echo $message; ?></p>
</form>
</body>
</html>