Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2. class Acceso {
  3. private $email;
  4. private $user;
  5. private $pass;
  6.  
  7. private function Encrypt($string) {
  8. $sizeof = strlen($string) -1;
  9. $result = '';
  10. for ($x =$sizeof; $x >= 0; $x--) {
  11. $result .= $string[$x];
  12. }
  13. $result = md5($result);
  14. return $result;
  15. }
  16.  
  17. public function Login() {
  18. try {
  19. if (!empty($_POST['user']) and !empty($_POST['pass']) and !empty($_POST['session'])) {
  20. $db = new Conexion();
  21. $this->user = $db->real_escape_string($_POST['user']);
  22. $this->pass = $this->Encrypt($_POST['pass']);
  23.  
  24. $sql = $db->query("SELECT * FROM users WHERE user='$this->user' AND pass='$this->pass';");
  25. if ($db->rows($sql) > 0) {
  26. $datos = $db->recorrer($sql);
  27. $_SESSION['user'] = $datos['user'];
  28. $_SESSION['user'] = $datos['user'];
  29. $_SESSION['email'] = $datos['email'];
  30. if ($_POST['session'] == true) { ini_set('session.cookie_lifetime', time() + (60*60*24*2));}
  31. echo 1;
  32. }
  33. else {
  34. throw new Exception(2);
  35.  
  36. }
  37. $db->liberar($sql);
  38. $db->close();
  39.  
  40.  
  41. }else {
  42. throw new Exception('ERROR: datos vacíos.');
  43.  
  44. }
  45. } catch (Exception $login) {
  46. echo $login->getMessage();
  47. }
  48.  
  49. }
  50. public function Recuperar() {
  51.  
  52. }
  53. public function Registrar() {
  54.  
  55. }
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement