Show sourcecode
The following files exists in this folder. Click to view.
Webserver1/Ovningar/Slutprojekt/
DEBUG/
Media/
header.php
index.php
login.php
signup.php
style.css
verifypage.php
signup.php
89 lines UTF-8 Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
<?php
session_start();
include('../../incl/dbconnection.php');
/**
* @var PDO $dbconn
*/
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inloggning</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="center-container" style="height: 95vh;">
<div>
<?php
print_r($_SESSION);
if (isset($_GET['reason'])) {
if ($_GET['reason'] == 'verifyTimeout') {
echo "<h4>Din kod löpte ut, vänligen försök igen!</h4>";
}
}
// Försök skapa konto
try {
// Hämta form data
$username = isset($_POST['username']) ? $_POST['username'] : null;
$email = isset($_POST['email']) ? $_POST['email'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
// Kolla om all data finns
if ($username && $password && $email) {
$hashedPass = password_hash($password, PASSWORD_BCRYPT);
$sqlSelect = "SELECT 1 FROM bay_users WHERE username=? OR email=?";
$selectStmt = $dbconn->prepare($sqlSelect);
$selectStmt->execute([$username, $email]);
$result = $selectStmt->fetch(PDO::FETCH_ASSOC);
if (!$result) {
$verificationCode = substr(md5(uniqid(rand())),0, 6);
// Lägg in relevanta variabler i SESSION (tas bort när konto skapats)
$_SESSION['verificationCode'] = $verificationCode;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['hashedPass'] = $hashedPass;
$_SESSION['verifyType'] = "CREATE";
header("Location:verifypage.php");
} else {
echo "<p class='text-center'>Användarnamn eller epost finns redan</p>";
}
}
} catch (PDOException $e) {
echo "<br>" . $e->getMessage();
}
?>
<form action="" method="post">
<h2>Skapa konto</h2>
<div class="row">
<label for="username">Användarnamn:</label>
<input type="text" name="username" id="username" autocomplete="off" required>
</div>
<div class="row">
<label for="email">Epost:</label>
<input type="email" name="email" id="email" autocomplete="off" required>
</div>
<div class="row">
<label for="password">Lösenord:</label>
<input type="password" name="password" id="password" autocomplete="off" required>
</div>
<div class="row">
<input type="submit" value="Skapa konto">
</div>
<div class="row">
<p style="font-size:small">Har redan ett konto? <a href="login.php">Logga in</a></p>
</div>
</div>
</div>
</form>
</body>
</html>