Almost finished login/register page
This commit is contained in:
18
website/queries/login.php
Normal file
18
website/queries/login.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function hashPassword() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`password`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`username` = :username
|
||||
");
|
||||
|
||||
$stmt->bindParam(":username", $_POST["uname"]);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
?>
|
||||
57
website/queries/register.php
Normal file
57
website/queries/register.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
function getExistingUser() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT * FROM `user` WHERE `username` = :username
|
||||
");
|
||||
|
||||
$stmt->bindParam(":username", $_POST["username"]);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
|
||||
}
|
||||
|
||||
function getExistingEmail() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT * FROM `user` WHERE `email` = :email
|
||||
");
|
||||
|
||||
$stmt->bindParam(":email", $_POST["email"]);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
function registerAccount() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
INSERT INTO
|
||||
`user`(fname,
|
||||
lname,
|
||||
birthdate,
|
||||
username,
|
||||
password,
|
||||
location,
|
||||
email)
|
||||
VALUES(
|
||||
:fname,
|
||||
:lname,
|
||||
:bday,
|
||||
:username,
|
||||
:password,
|
||||
:location,
|
||||
:email
|
||||
)");
|
||||
|
||||
$hash=password_hash($_POST["password"], PASSWORD_DEFAULT);
|
||||
|
||||
$stmt->bindParam(":fname", $_POST["name"]);
|
||||
$stmt->bindParam(":lname", $_POST["surname"]);
|
||||
$stmt->bindParam(":bday", $_POST["bday"]);
|
||||
$stmt->bindParam(":username", $_POST["username"]);
|
||||
$stmt->bindParam(":password", $hash);
|
||||
$stmt->bindParam(":location", $_POST["location"]);
|
||||
$stmt->bindParam(":email", $_POST["email"]);
|
||||
|
||||
print("execute".$stmt->execute());
|
||||
print("count".$stmt->rowCount());
|
||||
}
|
||||
?>
|
||||
@@ -10,9 +10,9 @@ function getSettings() {
|
||||
`birthdate`,
|
||||
`bio`,
|
||||
`profilepicture`
|
||||
FROM
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
@@ -43,4 +43,4 @@ function updateSettings() {
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user