-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.php
38 lines (30 loc) · 1.03 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
if (!isset($_POST['username'])){header('location: index.php');}
function encripitar($senha){
$salt = '/x!a@r-$r%an¨.&e&+f*f(f(a)';
$output = hash_hmac('md5', $senha, $salt);
return $output;
}
$password = $_POST['password'];
$username = $_POST['username'];
$encript = encripitar($password);
if($username !== '' && $password !== ''){
$host = "host=localhost";
$port = "port=5433";
$dbname = "dbname=postgres";
$credentials = "user=postgres password=159753456";
$conn = pg_connect( "$host $port $dbname $credentials" );
$query = "SELECT * FROM accounts WHERE login = '$username' AND password = '$encript';";
$result = pg_query($conn, $query);
$resultado = pg_num_rows($result);
$values = pg_fetch_all($result);
if(pg_num_rows($result) != 1){
echo "404";
}else{
header('Content-type: text/javascript');
echo json_encode($values, JSON_PRETTY_PRINT);
}
}else{
echo "<script>alert('Usuario ou senha esta incorreta.');</script><script>window.history.back()</script>";
}
?>