Guest User

Untitled

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. <?php
  2. include_once "conexion/clsConexion.php";
  3. require_once "recaptchalib.php";
  4. $obj = new clsConexion;
  5. $ip = $_SERVER['REMOTE_ADDR'];
  6. $consulta_ip = $obj->consultar("SELECT count(direccion_ip) AS login_intentos_fallidos FROM intentos_fallidos WHERE direccion_ip = '$ip' AND fecha_login_fallido BETWEEN DATE_SUB( NOW() , INTERVAL 1 DAY ) AND NOW()");
  7. foreach ((array) $consulta_ip as $row) {
  8. $intentos_fallidos = $row['login_intentos_fallidos'];
  9. }
  10. ?>
  11. <!DOCTYPE html>
  12. <html>
  13. <head>
  14. <meta charset="utf-8">
  15. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  16. <title>SANTA MARIA REYNA | Login</title>
  17. <!-- Tell the browser to be responsive to screen width -->
  18. <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  19. <!-- Bootstrap 3.3.6 -->
  20. <link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css">
  21. </head>
  22. <body background="fondo.jpg">
  23. <div class="login-box" id="todo-transparente">
  24. <!-- /.login-logo -->
  25. <div class="login-box-body">
  26. <div class="login-logo">
  27. <img src="configuracion/foto/<?php echo $logo ?>" width="150" height="150" />
  28. </div>
  29. <p class="login-box-msg">Por favor ingrese su codigo y clave.</p>
  30. <form name="form1" method="post" action="">
  31. <div class="form-group has-feedback">
  32. <input type="text" class="form-control" name="codigo" id="username" required placeholder="codigo" autocomplete="off" />
  33. <span class="glyphicon glyphicon-user form-control-feedback"></span>
  34. </div>
  35. <div class="form-group has-feedback">
  36. <input type="password" class="form-control" name="clave" id="password" required placeholder="clave" autocomplete="off" />
  37. <span class="glyphicon glyphicon-lock form-control-feedback"></span>
  38. </div>
  39. <?php if (isset($intentos_fallidos) && $intentos_fallidos >= 3) {?>
  40. <div class="g-recaptcha" data-sitekey="6LfKazQUAAAAABb5TdsXhiXtPoKiVfZrwkaPjnC_" data-theme="dark"></div>
  41. <?php }?>
  42. <div class="form-group has-feedback">
  43. <button type="submit" value="Ingresar" class="btn btn-primary btn-block btn-flat"> <i class="fa fa-unlock"></i> Entrar</button>
  44. </div>
  45. </form>
  46. <div align="center">
  47. <br />
  48. <span>2017</span> - <span>All rights reserved.</span>
  49. </div>
  50. </div>
  51. <!-- /.login-box-body -->
  52. <!-- /.login-box -->
  53. <!-- jQuery 2.2.3 -->
  54. <script src="plugins/plugins/jQuery/jquery-2.2.3.min.js"></script>
  55. <!-- Bootstrap 3.3.6 -->
  56. <script src="plugins/bootstrap/js/bootstrap.min.js"></script>
  57. </body>
  58. </html>
  59. <?php
  60. session_start();
  61. if (!empty($_POST['g-recaptcha-response'])) {
  62. //Asignas la clave secreta a una variable llamada $claveSecreta
  63. $claveSecreta = "6LfKazQUAAAAAJFGcTeZ4HfwKuRwvXTY3ZF_A3aR";
  64. // Por default asumimos que tenemos una respuesta vacía
  65. $respuesta = null;
  66. //Creamos una instancia de la clase que incluimos
  67. $captcha = new ReCaptcha($claveSecreta);
  68. //Validamos que si hayamos recibido por post la respuesta que recibimos de google al validar el captcha
  69. if ($_POST["g-recaptcha-response"]) {
  70. //Le pedimos a google que valide la respuesta del captcha para ello enviamos nuestro dominio y la respuesta
  71. $respuesta = $captcha->verifyResponse
  72. (
  73. $_SERVER['REMOTE_ADDR'],
  74. $_POST["g-recaptcha-response"]
  75. );
  76. }
  77. }
  78. if (!empty($_POST['codigo']) and !empty($_POST['clave'])) {
  79. $codigo = trim($obj->real_escape_string(htmlentities(strip_tags($_POST['codigo'], ENT_QUOTES))));
  80. $clave = trim($obj->real_escape_string(htmlentities(strip_tags($_POST['clave'], ENT_QUOTES))));
  81. $clavemd5 = md5($clave);
  82. $resultapo = $obj->consultar("select * from usuario where codigo='" . $obj->real_escape_string($codigo) . "' and clave='" . $obj->real_escape_string($clavemd5) . "'");
  83. foreach ((array) $resultapo as $row) {
  84. $valor = $row['codigo'];
  85. $estado = $row["estado"];
  86. $tipo = $row["tipo"];
  87. $obj->ejecutar("DELETE FROM intentos_fallidos WHERE direccion_ip = '$ip'");
  88. }
  89. //si el codigo no existe en la bd manda el mensaje de error es como decir $row['codigo']=nulo
  90. if (isset($valor) == '') {
  91. echo "<script>
  92. alertify.alert('Mensaje','Usuario y/o clave Incorrecta.', function(){
  93. alertify.message('OK');
  94. self.location='index.php';
  95. });
  96. </script>";
  97. if ($intentos_fallidos < 3) {
  98. $obj->ejecutar("INSERT INTO intentos_fallidos (direccion_ip,fecha_login_fallido) VALUES ('$ip', NOW())");
  99. }
  100. } else if ($estado != 'ACTIVO') {
  101. echo "<script>
  102. alertify.alert('Mensaje','Usted no se encuentra Activo en la base de datos.', function(){
  103. alertify.message('OK');
  104. self.location='index.php';
  105. });
  106. </script>";
  107. } else if ($tipo == 'ADMIN') {
  108. // esta sesion de autentificado lo pongo 1 para seguridad i despues haga la comprobacion si no es igual a 1 se redireccion al inicio
  109. $_SESSION["autentificado"] = 1;
  110. $_SESSION["codigo"] = $codigo;
  111. $_SESSION["clave"] = $clavemd5;
  112. header('location:inicio/index.php');
  113. }
  114. }
  115. ?>
Add Comment
Please, Sign In to add comment