Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/slutprojekt/

admin.php
bilder/
checkUpdates.php
confirmPassword.php
confirmSignIn.php
createadmin.php
endScreen.php
getBoard.php
getChat.php
getHand.php
getTurnPlayer.php
lobbies.php
logIn.php
play.php
playCard.php
signIn.php
start.php
startsida.php
style.css
tables.php
update.php
updatePassword.php
waitInfo.php
waitingRoom.php

updatePassword.php

57 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Jass</title>
</head>
<body>
  <?php
    
/** @var PDO $dbconn */
    
include ('../dbconnection.php');

    if (isset(
$_POST["name"]) && isset($_POST["pwd"])) {
      
$name htmlspecialchars($_POST["name"]);

      try {
        
$sql "SELECT * FROM JassPlayers WHERE username=?";
        
$stmt $dbconn->prepare($sql);

        
$data = array($name);
        
$stmt->execute($data);

        if (
$player $stmt->fetch(PDO::FETCH_ASSOC)) {
          
$mail $player["mail"];
          
$pwd htmlspecialchars($_POST["pwd"]);
          
$mailId rand(0,999999);

          
setcookie("newpwd"$pwdtime() + 900);
          
setcookie("mailId"$mailIdtime() + 900);
          
setcookie("name"$nametime() + 900);

          if (
$local) {
            
header("location: http://localhost/slutprojekt/confirmPassword.php?mailId=$mailId");
          } else {
            
$msg "Go to this link \n
            https://labb.vgy.se/~teorut23/webbsrvprg/slutprojekt/confirmPassword.php?mailId=
$mailId";
            
mail($mail"Confirm mail"$msg);
          }

          echo 
"A mail has been sent to your e-mail.";
        }
      } catch (
PDOException $e) {
        echo 
$sql "<br>" $e->getMessage();
      }
    }
  
?>

  <!-- Inloggningsformulär -->
  <form action="" method="post">
    <h1>Enter username to update password</h1>
    <input type="text" name="name" placeholder="Username"> <br>
    <input type="text" name="pwd" placeholder="New password"> <br>

    <input type="submit" value="Send mail">
  </form>
</body>
</html>