-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginsubmit.php
64 lines (60 loc) · 1.57 KB
/
loginsubmit.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
session_start();
require_once("databaseconnection.php");
function selectUsers(){
global $test;
$user=filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
$query = "SELECT user_name FROM user_name
WHERE user_name='$user'";
$statement = $test->prepare($query);
$statement->execute();
if ($statement->rowCount()) {
return TRUE;
}
else{
return FALSE;
}
}
$user_name=selectUsers();
function selectPassword() {
global $test;
$user=filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
$password=filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
$query = "SELECT user_name FROM user_name
WHERE user_name='$user'
AND password=AES_ENCRYPT('$password', 'test')";
$statement = $test->prepare($query);
$statement->execute();
if ($statement->rowCount()) {
return TRUE;
echo "password is correct";
}
else{
return FALSE;
echo "password is incorrect";
}
}
$password = selectPassword();
if($user_name == TRUE){
echo "user exists";
if($password == TRUE){
$user=filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
$_SESSION['user']=$user;
$location = "Location: whybuy.php";
$_SESSION['loginsuccess']="Welcome $user!";
//$_SESSION['password']=$password;
//$_SESSION['user_level']=$user_level;
echo "password is correct";
}
else{
$_SESSION["login_msg"] = "invalid password";
$location = "Location: login.php";
echo "password is invalid";
}
}
else{
$_SESSION["login_msg"] = "user does not exist";
$location = "Location: login.php";
}
header($location);
?>