diff --git a/login.php b/login.php new file mode 100644 index 0000000..15cdc4b --- /dev/null +++ b/login.php @@ -0,0 +1,46 @@ +prepare("SELECT * FROM users WHERE email = :email"); + $result = $statement->execute(array('email' => $email)); + $user = $statement->fetch(); + + //Überprüfung des Passworts + if ($user !== false && password_verify($passwort, $user['passwort'])) { + $_SESSION['userid'] = $user['id']; + die('successfull. go to: secure page'); + } else { + $errorMessage = "somethings wrong (maybe wrong password or wrong email)
"; + } + +} +?> + + + + Login + + + + + +
+E-Mail:
+

+ +Dein Passwort:
+
+ + +
+ + \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..78d136b --- /dev/null +++ b/register.php @@ -0,0 +1,82 @@ + + + + + Register + + + +'; + $error = true; + } + if(strlen($passwort) == 0) { + echo 'Please enter password
'; + $error = true; + } + if($passwort != $passwort_confirm) { + echo 'passwords doesnt match
'; + $error = true; + } + + + if(!$error) { + $statement = $pdo->prepare("SELECT * FROM users WHERE email = :email"); + $result = $statement->execute(array('email' => $email)); + $user = $statement->fetch(); + + if($user !== false) { + echo 'already a user here
'; + $error = true; + } + } + + if(!$error) { + $passwort_hash = password_hash($passwort, PASSWORD_DEFAULT); + + $statement = $pdo->prepare("INSERT INTO users (email, passwort) VALUES (:email, :passwort)"); + $result = $statement->execute(array('email' => $email, 'passwort' => $passwort_hash)); + + if($result) { + echo 'successfull registered. Login'; + $showFormular = false; + } else { + echo 'Error. Please try again!
'; + } + } +} + +if($showFormular) { +?> + +
+E-Mail:
+

+ +Password:
+
+ +Password (aganin):
+

+ + +
+ + + + + \ No newline at end of file diff --git a/secure.php b/secure.php new file mode 100644 index 0000000..4a42e31 --- /dev/null +++ b/secure.php @@ -0,0 +1,12 @@ +login'); +} + +$userid = $_SESSION['userid']; + +echo "Hi ".$userid; +echo "
" +echo "This is secure now!" +?> \ No newline at end of file diff --git a/usertable.sql b/usertable.sql new file mode 100644 index 0000000..46b7669 --- /dev/null +++ b/usertable.sql @@ -0,0 +1,10 @@ +CREATE TABLE `users` ( + `id` INT NOT NULL AUTO_INCREMENT , + `email` VARCHAR(255) NOT NULL , + `passwort` VARCHAR(255) NOT NULL , + `vorname` VARCHAR(255) NOT NULL DEFAULT '' , + `nachname` VARCHAR(255) NOT NULL DEFAULT '' , + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , + `updated_at` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , + PRIMARY KEY (`id`), UNIQUE (`email`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file