Advertisement
FabianoSouzaPereira

alunos.com.br/login.php

Feb 7th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <?php
  2. session_start ();
  3. // include 'DAO/conection.php';
  4. require_once 'init.php';
  5.  
  6. if (! empty ( $_POST )) {
  7.     $user = $_POST ['user'];
  8.     $password = $_POST ['password'];
  9.     $has_cod = md5($password);
  10.     try {
  11.        
  12.     //  $sql = ( "SELECT id, user, password From users where user=:user and password= :has_cod;" );
  13.         $stmt = $pdo->prepare("SELECT user, password From users where user= :user and password= :has_cod;" );
  14.         $stmt->bindParam ( ':user', $user, PDO::PARAM_STR );
  15.         $stmt->bindParam ( ':has_cod', $has_cod, PDO::PARAM_STR);
  16.        
  17.         // Executa query
  18.         $stmt->execute ();
  19.        
  20.         while ( $obj = $stmt->fetch ( PDO::FETCH_ASSOC ) ) {
  21.             $obj {[
  22.                     'id'
  23.             ]};
  24.             $obj {[
  25.                     'user'
  26.             ]};
  27.         }
  28.        
  29.         if (empty ( $obj )) {
  30.             echo "<script>alert('Seu login falhou. LOGIN: admin@admin.com SENHA: 1234');</script>";
  31.         } else {
  32.             $_SESSION ['logado'] = true;
  33.             $_SESSION ['id'] = $obj ['id'];
  34.             $_SESSION ['user'] = $obj ['user'];
  35.             header ( "location: index.php" );
  36.         }
  37.     } catch ( PDOException $e ) {
  38.         echo "Error: " . $e;
  39.     }
  40. }
  41. ?>
  42.  
  43.  
  44. <!Doctype html>
  45. <html lang="pt-br">
  46. <head>
  47. <title>Cadastro de Alunos</title>
  48. <meta charset="utf8">
  49. <!-- Chamada do CSS -->
  50. <link rel="stylesheet" href="css/estilo.css">
  51. <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
  52.  
  53. <script src="bootstrap/js/jquery-1.12.4.min.js"></script>
  54. <script src="bootstrap/js/bootstrap.min.js"></script>
  55. </head>
  56.  
  57. <body>
  58.  
  59.     <form id="login" action="" method="post" class="panel panel-warning">
  60.  
  61.         <div class="panel-heading">
  62.             <h3>Acesso Restrito - Faça seu login</h3>
  63.         </div>
  64.  
  65.         <div class="panel-body">
  66.  
  67.             <div class="form-group">
  68.                 <label for="email">E-mail</label> <input type="text"
  69.                     class="form-control" name="user" id="user"
  70.                     placeholder="Digite seu e-mail de acesso" required autofocus>
  71.             </div>
  72.  
  73.  
  74.             <div class="form-group">
  75.                 <label for="senha">Senha</label>
  76.                 <input type="password"  class="form-control" name="password" id="password"   autocomplete="off" placeholder="Digite sua senha" required autofocus>
  77.             </div>
  78.  
  79.             <div class="form-group">
  80.                 <input type="submit" class="btn btn-success" value="Acessar"  autocomplete="off"> <a href="" class="label label-warning" style="float: right;">Esqueci a senha!</a>
  81.             </div>
  82.  
  83.         </div>
  84.     </form>
  85.  
  86. </body>
  87.  
  88. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement