Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. <?php
  2. require 'core.php';
  3. if (isRegistration())  {
  4.         $pdo = createPDO();
  5.         $sql = "INSERT INTO user (login, password) VALUES (?, ?)";
  6.         $statement = $pdo->prepare($sql);
  7.         $userPassword = getHashPassword($_POST['password']);
  8.         $statement->execute(["{$_POST['login']}", "{$userPassword}"]);
  9. }
  10. if (isAuthorization()) {
  11.         $pdo = createPDO();
  12.         $sql = "SELECT * FROM user WHERE login = ? AND password = ?";
  13.         $statement = $pdo->prepare($sql);
  14.         $userPassword = getHashPassword($_POST['password']);
  15.         $statement->execute(["{$_POST['login']}", "{$userPassword}"]);
  16.     $user = $statement->fetch(PDO::FETCH_ASSOC);
  17.         if (!empty($user)) {
  18.             session_start();
  19.             unset($user['password']);
  20.             $_SESSION['user'] = $user;
  21.             header('Location: ./index.php');
  22.         }
  23. }
  24. ?>
  25.  
  26. <!DOCTYPE html>
  27. <html lang="en">
  28.   <head>
  29.     <meta charset="utf-8">
  30.     <title>Вход</title>
  31.         <style>
  32.           body {
  33.                 background-color: #E1F0FF;
  34.                 text-align: center;
  35.                 color: #6A6BA3;
  36.             }
  37.           form {
  38.                 display: inline-block;
  39.                 width: 220px;              
  40.             }
  41.             input {
  42.                 margin: 0 0 20px 0;
  43.                 color: #0000CD;
  44.             }
  45.             button {
  46.                 color: #000080;
  47.             }
  48.         </style>
  49.   </head>
  50.   <body>
  51.     <form method="POST">
  52.           <p style="display: inline-block;"><b><?php if (isRegistration()) {
  53.               echo 'Ваши данные отправлены! Войдите, используя свой логин и пароль:'; } else if (isAuthorization() && empty($user)) { echo 'Неправильный логин и пароль!'; } else { echo 'Войдите или зарегистрируйтесь:'; } ?></b></p>
  54.       <input name="login" id="login" placeholder="Логин">
  55.       <input name="password" id="password" placeholder="Пароль">
  56.             <button type="submit" name="registration">Регистрация</button>
  57.             <button type="submit" name="authorization">Вход</button>
  58.     </form><br>
  59.   </body>
  60. </html>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement