Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/quiz/
admin.php
dbconnection.php
glömtLösen.php
index.php
quiz.php
quiz_css.css
rättning.php
skapaTabell.php
verify.php
glömtLösen.php
59 lines UTF-8 Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
include ('dbconnection.php');
if (isset($_POST["epost"])) {
$sql = "SELECT * FROM QUIZAnvändare WHERE epost=?";
$stmt = $dbconn->prepare($sql);
$data = array($_POST["epost"]);
$stmt->execute($data);
$antalposter = $stmt->rowCount();
if ($antalposter==1) {
$meddelande = "<!DOCTYPE html>
<html lang='sv'>
<head>
<meta charset='utf-8' />
<title>Förnya lösen</title>
<style>
body{
font-family: arial;
background-color: #555;
}
form{
margin: auto;
top: 90px;
border:1px #000 solid;
width: 500px;
padding: 20px;
background-color: #999;
margin-bottom: 15px;
}
</style>
</head>
<body>
Gör ett nytt lösenord<br>
<form action='http://labb.vgy.se/~albinbm/webbserverprogrammering/exercises/quiz/glömtLösen.php' method='post'>
Lösenord: <input type='password' name='regpass' id='pass'>
<input type='hidden' name='epost2' value='".$_POST["epost"]."'>
<input type='submit' value='Uppdatera'>
</form>
</body>
</html>";
mail($_POST["epost"], "Byt lösenord", $meddelande, 'From: noreply@albinsquiz.vgy' . "\r\n" . "MIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO-8859-1\r\n");
echo "<script type='text/javascript'>alert('Ett epostmeddelande om återställning har skickats till:".$_POST["epost"]."');window.location.href = 'index.php';</script>";
}
else echo "Epost adressen du angav finns inte registrerad";
}
elseif(isset($_POST["regpass"]) && isset($_POST["epost2"])){
$password = password_hash($_POST["regpass"], PASSWORD_DEFAULT);
$sql = "UPDATE QUIZAnvändare SET password = ?
WHERE epost =?";
$stmt = $dbconn->prepare($sql);
$data = array($password, $_POST["epost2"]);
$stmt->execute($data);
echo "<script type='text/javascript'>alert('Lösenordet har uppdaterats');window.location.href = 'index.php';</script>";
}
?>