0% found this document useful (0 votes)
32 views

If ($model - Row ('User - Hivi') $user && $model - Row ('Pass - Hivi') $pass && $model - Row ('State - User') 1) (

This PHP code validates user login credentials by calling a Database model to check if the submitted username and password match those stored for a user account with a state of 1. If credentials are valid, session variables are set and the user is redirected to the home page. Otherwise, an error message is stored in a session variable and the user is redirected back to the login page. It also checks that required fields and CAPTCHAs are submitted correctly.

Uploaded by

Niac Bela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

If ($model - Row ('User - Hivi') $user && $model - Row ('Pass - Hivi') $pass && $model - Row ('State - User') 1) (

This PHP code validates user login credentials by calling a Database model to check if the submitted username and password match those stored for a user account with a state of 1. If credentials are valid, session variables are set and the user is redirected to the home page. Otherwise, an error message is stored in a session variable and the user is redirected back to the login page. It also checks that required fields and CAPTCHAs are submitted correctly.

Uploaded by

Niac Bela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

<?

php
2
3 require_once 'app/models/Database.php';
4
5 class Validate_login {
6
7 public function validateLogin($user,
($user, $pass) {
8 //Instanciamos el modelo...
9 $model = new Database();
10 $model->validar_login($user, $pass);
11 //print_r($model->row);
12 //exit();
13 //Comparamos los datos obtenidos...
14 if ($model->row['user_hivi'] == $user && $model->row['pass_hivi'] == $pass && $model->row['state_user'] == 1) {
15 //Creamos variables de sesion...
16 $_SESSION['sesion_hivi'] = true;
17 $_SESSION['user_hivi'] = $model->row['user_hivi'];
18 $_SESSION['btc_user'] = $model->row['btc_user'];
19 //Redireccionamos al dashboard...
20 header("Location: " . BASE_URL . "home/");
21 } else {
22 //Creamos una variable de error...
23 $_SESSION['notify'] = "<div class='alert alert-dismissible alert-danger'>The account does not exist, check the data and try again.</div>";
24 header("Location: " . BASE_URL . "login/");
25 }
26 }
27
28 }
29
30 if (isset($_POST['login'])) {
31 //Validamos que los dato sno esten vacios...
32 if (empty($_POST['username']) or empty($_POST['password'])) {
//Creaos una variable de notificacion...
$_SESSION['notify'] = "<div class='alert alert-dismissible alert-danger'>The form fields are required.</div>";
header("Location: " . BASE_URL . "login/");
} elseif ($_POST['captcha'] != $_SESSION['tmptxt']) {
$_SESSION['notify'] = "<div class='alert alert-dismissible alert-danger'>The validation CAPTCHA is incorrect.</div>";
header("Location: " . BASE_URL . "login/");
} else {
//Recogemos los datos del formulario...
$user = $_POST['username'];
$pass = $_POST['password'];
$captcha = $_POST['captcha'];
$newlogin = new Validate_login();
$newlogin->validateLogin($user, $pass);
}
} else {
header("Location: " . BASE_URL . "login/");
}

1.1 of 1 2020.04.10 15:00:58

You might also like