Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- echo("<!DOCTYPE html><html>");
- if($_POST)
- {
- $con = @new mysqli('localhost', 'pedro', 'pedro', 'pedro');
- if($con->connect_errno)
- {
- die(utf8_encode($con->connect_error));
- }
- if(!isset($_SESSION['LOGGED']))
- {
- if(isset($_POST['user']) && !empty($_POST['user']) && isset($_POST['pass']) && !empty($_POST['pass']))
- {
- if($r = $con->query("SELECT * FROM users WHERE name='".addslashes($_POST['user'])."' and pass='".addslashes($_POST['pass'])."'"))
- {
- if($r->num_rows == 1)
- {
- $row = $r->fetch_assoc();
- $_SESSION['LOGGED'] = $row['id'];
- echo("<script>alert('Bienvenido ".$row['name']."')</script>");
- }
- else
- {
- echo("<script>alert('Error en los datos suministrados')</script>");
- }
- }
- }
- else
- {
- echo('<script>alert(\'Verifica que todos los campos esten completos\')</script>');
- }
- }
- else
- {
- if(isset($_POST['pass']) && !empty($_POST['pass']))
- {
- if($con->query("UPDATE users SET pass='".addslashes($_POST['pass'])."' WHERE id='".$_SESSION['LOGGED']."'"))
- {
- echo("<script>alert('Clave Cambiada con exito')</script>");
- session_unset();
- }
- else
- {
- echo("<script>alert('Hubo un error al cambiar la pass')</script>");
- }
- }
- }
- $con->close();
- }
- ?>
- <?php if(!isset($_SESSION['LOGGED'])): ?>
- <head>
- <meta charset="utf-8">
- <title>Inicio</title>
- </head>
- <body>
- <form method="post">
- <label><strong>User</strong></label><br>
- <input type="text" name="user" placeholder="Usuario"><br>
- <label><strong>Pass</strong></label><br>
- <input type="password" name="pass"><br>
- <button type="submit">Enviar</button>
- </form>
- </body>
- </html>
- <?php else:?>
- <head>
- <meta charset="utf-8">
- <title>Clave</title>
- </head>
- <body>
- <form method="post">
- <label><strong>Clave Nueva</strong></label><br>
- <input type="password" name="pass"><br>
- <button type="submit">Enviar</button>
- </form>
- </body>
- </html>
- <?php endif;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement