Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/slutprojekt/
actions.php
administer_users.php
create_code.php
database_include.php
dbconnection.php
index.php
login copy.php
login.php
main.php
password_renewals.php
play copy.php
play.php
setup.php
sign_up.php
statistics.php
verification.php
verify_mail.php
database_include.php
61 lines UTF-8 Windows (CRLF)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
<?php
include("dbconnection.php");
/** @var PDO $dbconn */
class DBActions
{
private PDO $dbconn;
public function __construct(PDO $dbconn)
{
$this->dbconn = $dbconn;
}
public function DltOldPswrdRenewals(): void
{
$this->dbconn->exec("DELETE FROM bs_password_renewals WHERE time_sent < NOW() - INTERVAL 15 MINUTE");
return;
}
public function SelectPswrdRenewals($user_id, $code): array
{
$sql = "SELECT * FROM bs_password_renewals WHERE user_id = ? AND code = ?";
$stmt = $this->dbconn->prepare($sql);
$data = [$user_id, $code];
$stmt->execute($data);
$info = $stmt->fetch(PDO::FETCH_ASSOC);
return ($info);
}
public function UpdatePswrd($new_password, $user_id): void
{
$sql = "UPDATE bs_users SET password = ? WHERE id = ?";
$stmt = $this->dbconn->prepare($sql);
$data = [$new_password, $user_id];
$stmt->execute($data);
return;
}
public function SelectUserIdAndMail($identifyer): array
{
$sql = "SELECT id, mail FROM bs_users WHERE username = ? OR mail = ?";
$stmt = $this->dbconn->prepare($sql);
$data = [$identifyer, $identifyer];
$stmt->execute($data);
$info = $stmt->fetch(PDO::FETCH_ASSOC);
return ($info);
}
public function CreatePswrdRenewal($user_id, $code, $hashed_password): void
{
$sql = "INSERT INTO bs_password_renewals (user_id, code, password) values(?,?,?)";
$stmt = $this->dbconn->prepare($sql);
$data = [$user_id, $code, $hashed_password];
$stmt->execute($data); // Är nu redo att verifieras. Ej bytt ännu.
return;
}
}
$dbActions = new DBActions($dbconn);