Advertisement
Sugisaki

OSWEE

Mar 2nd, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.97 KB | None | 0 0
  1. <?php
  2. session_start();
  3. echo("<!DOCTYPE html><html>");
  4. if($_POST)
  5. {
  6.     $con = @new mysqli('localhost', 'pedro', 'pedro', 'pedro');
  7.  
  8.     if($con->connect_errno)
  9.     {
  10.         die(utf8_encode($con->connect_error));
  11.     }
  12.  
  13.     if(!isset($_SESSION['LOGGED']))
  14.     {
  15.         if(isset($_POST['user']) && !empty($_POST['user']) && isset($_POST['pass']) && !empty($_POST['pass']))
  16.         {
  17.              
  18.             if($r = $con->query("SELECT * FROM users WHERE name='".addslashes($_POST['user'])."' and pass='".addslashes($_POST['pass'])."'"))
  19.             {
  20.                 if($r->num_rows == 1)
  21.                 {
  22.                     $row = $r->fetch_assoc();
  23.                     $_SESSION['LOGGED'] = $row['id'];
  24.                     echo("<script>alert('Bienvenido ".$row['name']."')</script>");
  25.                 }
  26.                 else
  27.                 {
  28.                     echo("<script>alert('Error en los datos suministrados')</script>");
  29.                 }
  30.             }
  31.  
  32.         }
  33.         else
  34.         {
  35.             echo('<script>alert(\'Verifica que todos los campos esten completos\')</script>');
  36.         }
  37.     }
  38.     else
  39.     {
  40.         if(isset($_POST['pass']) && !empty($_POST['pass']))
  41.         {
  42.             if($con->query("UPDATE users SET pass='".addslashes($_POST['pass'])."' WHERE id='".$_SESSION['LOGGED']."'"))
  43.             {
  44.                 echo("<script>alert('Clave Cambiada con exito')</script>");
  45.                 session_unset();
  46.             }
  47.             else
  48.             {
  49.                 echo("<script>alert('Hubo un error al cambiar la pass')</script>");
  50.             }
  51.         }
  52.        
  53.     }
  54.     $con->close();
  55.  
  56.    
  57. }
  58.  
  59. ?>
  60. <?php if(!isset($_SESSION['LOGGED'])): ?>
  61.  
  62. <head>
  63.     <meta charset="utf-8">
  64.     <title>Inicio</title>
  65. </head>
  66. <body>
  67. <form method="post">
  68.     <label><strong>User</strong></label><br>
  69.     <input type="text" name="user" placeholder="Usuario"><br>
  70.     <label><strong>Pass</strong></label><br>
  71.     <input type="password" name="pass"><br>
  72.     <button type="submit">Enviar</button>
  73. </form>
  74. </body>
  75. </html>
  76. <?php else:?>
  77.  
  78. <head>
  79.     <meta charset="utf-8">
  80.     <title>Clave</title>
  81. </head>
  82. <body>
  83. <form method="post">
  84.     <label><strong>Clave Nueva</strong></label><br>
  85.     <input type="password" name="pass"><br>
  86.     <button type="submit">Enviar</button>
  87. </form>
  88. </body>
  89. </html>
  90. <?php endif;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement