protected static function connect() { // Establece una conexión con el servidor MySQL. Con los datos definidos en el archivo 'conf/settings.php'. @(self::$_db_connect = new mysqli(DB_HOST, DB_USER, DB_PASS)); // En caso de que la conexión no se establezca por algún error. if (self::$_db_connect->connect_error) { self::regError(true); // Registra el error en el archivo log/error_log.txt. self::showMessage("Error al conectar con la Base de Datos, vuelva a intentarlo más tarde"); // Muestra al usuario un mensaje de advertencia. return false; } // Selecciona la BD a utilizar en la conexión establecida anteriormente. La BD se establece en el archivo 'conf/settings.php'. $db_select = self::$_db_connect->select_db(DB_SELECT); // En caso de no haber seleccionado la BD. if (!$db_select) { self::regError(); // Registra el error en el archivo log/error_log.txt. self::showMessage("Error al seleccionar la Base de Datos, vuelva a intentarlo más tarde"); // Muestra al usuario un mensaje de advertencia. return false; } // Establece una codificación a la conexión. self::$_db_connect->set_charset(DB_CHARSET); return true; }
private function regUser() { $sql = "INSERT INTO users (firstname, lastname, email, pass, reg_date)\n VALUES ('{$this->firstname}', '{$this->lastname}', '{$this->email}', '{$this->password}', '{$this->dateTime}');"; $query = $this->_db_connect->query($sql); if ($query === false) { parent::regError(); $this->showMessage("No se ha podido registrar el usuario, vuelva a intentarlo más tarde."); $this->closeConnect(); return false; } $this->closeConnect(); return true; }
private function noIssetNickName() { $this->_sql = "SELECT id FROM users WHERE login = '******';"; $query = parent::$_db_connect->query($this->_sql); if ($query === false) { parent::errorResult("No se ha podido comprobar la existencia del Login, vuelva a intentarlo más tarde.", true); return false; } if ($query->num_rows == 0) { return true; } else { return false; } }
private function check() { $sql = "SELECT u.id, u.firstname, u.lastname, u.email, u.password, u.profile_img FROM users u WHERE email = '" . $this->email . "'"; $query = $this->_db_connect->query($sql); if (!$query) { parent::regError(); $this->showMessage($this->getTextLang("generic_error")); $this->closeConnect(); return false; } elseif ($query->num_rows == 0) { $this->showMessage($this->getTextLang("log_user_not_exist")); $this->closeConnect(); return false; } else { if ($row = $query->fetch_assoc()) { if (password_verify($this->pass, $row['password'])) { $_SESSION['user'] = array(); $_SESSION['user']['id'] = $row['id']; $_SESSION['user']['name'] = $row['firstname']; $_SESSION['user']['lastname'] = $row['lastname']; $_SESSION['user']['img'] = $row['profile_img']; $_SESSION['user']['email'] = $row['email']; } else { $this->showMessage("La contraseña no es válida"); $this->closeConnect(); return false; } } else { parent::regError(); $this->showMessage($this->getTextLang("generic_error")); $this->closeConnect(); return false; } } $this->closeConnect(); return true; }
<thead> <tr> <th>Sno</th> <th>Customer ID</th> <th>Merchant ID</th> <th>Age</th> <th>Sex</th> <th>Amount</th> <th>Time</th> <th>Date</th> </tr> </thead> <tbody> <?php require '../DataBaseConnect.php'; $database = new DataBaseConnect(); $result = $database->execute_query_return("select * from `transactions`"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['sno'] . "</td>"; echo "<td>" . $row['cid'] . "</td>"; echo "<td>" . $row['mid'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['sex'] . "</td>"; echo "<td>" . $row['amount'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "</tr>"; } ?>
<?php require 'DataBaseConnect.php'; $database = new DataBaseConnect(); ?> <html> <head> <title>View Customer Transactions</title> </head> <body leftmargin="450"> <img src="img/User.png" /><br> Name: Anubhav<br> Age: 21<br> Mobile: 9591279206<br> Sex: Male<br><br> <table border="1"> <tr> <td>Sno</td> <td>Customer ID</td> <td>Merchant ID</td> <td>Age</td> <td>Sex</td> <td>Amount</td> <td>Time</td> <td>Date</td> </tr> <?php $result = $database->execute_query_return("select * from `transactions` where `cid`=119555"); while ($row = mysql_fetch_array($result)) {
<?php require 'DataBaseConnect.php'; $database = new DataBaseConnect(); ?> <html> <head> <title>Merchant Details</title> </head> <body leftmargin="450"> <img src="img/User.png" /><br> Merchant name: McDonalds<br> ID: 58<br><br> <table border="1"> <tr> <td>Sno</td> <td>Customer ID</td> <td>Customer Name</td> <td>Balance</td> <td>Mobile</td> </tr> <?php $result = $database->execute_query_return("select * from `merchant1`"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['sno'] . "</td>"; echo "<td>" . $row['cid'] . "</td>"; echo "<td>" . $row['cname'] . "</td>"; echo "<td>" . $row['balance'] . "</td>";
/** * @return bool */ private function check() { $this->_sql = "SELECT * FROM users WHERE login = '******';"; $query = parent::$_db_connect->query($this->_sql); if (!$query) { parent::errorResult("Se ha producido algún error vuelva a intentarlo más tarde", true); return false; } elseif ($query->num_rows == 0) { self::$access_error++; parent::errorResult("¡El usuario introducido no existe!"); return false; } else { if ($row = $query->fetch_assoc()) { if (password_verify($this->pass, $row['pass'])) { if (self::$access_error > 3 && isset($_POST['captcha']) && $_POST['captcha'] == $_COOKIE['key']) { $_SESSION['user'] = array(); $_SESSION['user']['id'] = $row['id']; $_SESSION['user']['login'] = $row['login']; $_SESSION['user']['pass'] = $row['pass']; $_SESSION['user']['name'] = $row['nombre']; $_SESSION['user']['firma'] = $row['firma']; $_SESSION['user']['email'] = $row['email']; $_SESSION['user']['avatar'] = $row['avatar']; $_SESSION['user']['tipo'] = $row['tipo']; $dateTime = new DateTime(); $_SESSION['user']['time'] = $dateTime->format('d-m-Y H:i:s'); } elseif (self::$access_error <= 3) { $_SESSION['user'] = array(); $_SESSION['user']['id'] = $row['id']; $_SESSION['user']['login'] = $row['login']; $_SESSION['user']['pass'] = $row['pass']; $_SESSION['user']['name'] = $row['nombre']; $_SESSION['user']['firma'] = $row['firma']; $_SESSION['user']['email'] = $row['email']; $_SESSION['user']['avatar'] = $row['avatar']; $_SESSION['user']['tipo'] = $row['tipo']; $dateTime = new DateTime(); $_SESSION['user']['time'] = $dateTime->format('d-m-Y H:i:s'); } else { $this->captchaFail = "El 'Captcha' no es válido"; parent::closeConnect(); return false; } } else { self::$access_error++; parent::errorResult("La contraseña no es válida."); return false; } } else { parent::errorResult("Se ha producido algún error vuelva a intentarlo más tarde", true); return false; } } parent::closeConnect(); return true; }
echo $str; $tok = strtok($string, "#"); $args = array(); echo $str; while ($tok !== false) { $args += $tok; echo $tok; $tok = strtok("#"); } return $args; } ?> <?php require 'DataBaseConnect.php'; $database = new DataBaseConnect(); // $mid = rand(10,100); // $cid = rand(100000,1000000); // $amount = rand(1,10000); // $age = rand(15,90); // $sex = rand(1,2); date_default_timezone_set('Asia/Kolkata'); $time = (string) date("H:i"); $date = date("d/m/Y"); // $database->execute_query_update("INSERT INTO `transactions`(`cid`, `mid`, `age`, `sex`, `amount`, `time`, `date`) VALUES (".$cid.",".$mid.",".$age.",".$sex.",".$amount.",'".$time."','".$date."')"); try { $mid = $_GET['mid']; $cid = $_GET['cid']; $amount = $_GET['amount']; $age = $_GET['age']; $sex = $_GET['sex'];
<?php require 'DataBaseConnect.php'; $database = new DataBaseConnect(); ?> <html> <head> <title>View Customer Transactions</title> </head> <body> <table border="1"> <tr> <td>Sno</td> <td>Customer ID</td> <td>Merchant ID</td> <td>Age</td> <td>Sex</td> <td>Amount</td> <td>Time</td> <td>Date</td> </tr> <?php $result = $database->execute_query_return("select * from `transactions` where cid=805707"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['sno'] . "</td>"; echo "<td>" . $row['cid'] . "</td>"; echo "<td>" . $row['mid'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['sex'] . "</td>";
/** * @return bool * * Actualiza los campos tan solo relacionados con la contraseña y realiza sus respectivas comprobaciones. * 1.- Comprueba que los campos del formulario relacionados con la contraseña no esten vacios. * 2.- Comprueba que la nueva contraseña cumpla los requisitos que debe tener la contraseña (min 8 car, 1 mayu, 1 min y 1 num). * 3.- Comprueba que la contraseña antigua sea igual que la que el usuario ha introducido en el campo de 'Contraseña antigua'. * 4.- Comprueba que la nueva contraseña y su repetición sean iguales. * */ private function passUpdate() { if (empty($this->old) && empty($this->new) && empty($this->renew)) { return false; } else { if (preg_match("/(?=^.{8,}\$)((?=.*\\d)|(?=.*\\W+))(?=.*[A-Z])(?=.*[a-z]).*\$/", $this->new)) { if (password_verify($this->old, $_SESSION['user']['pass'])) { if ($this->new == $this->renew) { /** * Este código evaluará el servidor para determinar el coste permitido. * Se establecerá el mayor coste posible sin disminuir demasiando la velocidad * del servidor. 8-10 es una buena referencia, y más es bueno si los servidores * son suficientemente rápidos. El código que sigue tiene como objetivo un tramo de * ≤ 50 milisegundos, que es una buena referencia para sistemas con registros interactivos. */ $timeTarget = 0.05; // 50 milisegundos $coste = 8; do { $coste++; $inicio = microtime(true); $this->new = password_hash($this->new, PASSWORD_BCRYPT, ["cost" => $coste]); $fin = microtime(true); } while ($fin - $inicio < $timeTarget); } else { $this->newFail = "Las nuevas contraseñas no coinciden"; return false; } } else { $this->oldFail = "La contraseña introducida no coincide con la anterior"; return false; } } else { $this->newFail = "La nueva contraseña no cumple los requisitos"; return false; } // Establece la conexión a la BD. parent::connect(); $this->_sql = "UPDATE users SET pass = '******' WHERE login = '******'user']['login'] . "';"; $query = parent::$_db_connect->query($this->_sql); if ($query === false) { parent::errorResult("¡No se a podido actualizar la contraseña!", true); return false; } return true; } }