-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.php
executable file
·40 lines (33 loc) · 959 Bytes
/
auth.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
39
40
<?php
// pass the username and password (thru https)
function auth($username, $password) {
$srv = "localhost";
$user = "root";
$pass = "pinetree";
$db = "login_db";
// connect to auth database
$conn = mysqli_connect($srv,$user,$pass,$db);
if(!$conn){
$ret['status'] = "-1";//"failed db connection";
return json_encode($ret);
}
//$username = $_POST['username'];
//$password_hash = password_hash($_POST['password']);
$res = mysqli_query($conn, "SELECT * FROM user");
$row = mysqli_fetch_array($res);
if(!$res){
$ret['status'] = '-3';
return json_encode($ret);// no user found in table
}
// verify hashed password
if($username==$row['username'] && password_verify($password,$row['password_hash'])){
$ret['status'] = "1";// ok
}else{
$ret['status'] = "0";//"incorrect login";
}
//$pass = mysqli_fetch_field($res);
//$ret['pass'] = $pass;
mysqli_close($conn);
return json_encode($ret);
}
?>