-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentlogin.php
56 lines (43 loc) · 1.23 KB
/
studentlogin.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
<?php
if(isset($_POST["username"]) && isset($_POST["password"])){
$errors = array();
$username = $_POST["username"];
$password = $_POST["password"];
//Connect to database
require dirname(__FILE__) . '/taylorstest.php';
if ($stmt = $mysqli_conection->prepare("SELECT username,password FROM student_logins WHERE username = ? LIMIT 1")) {
/* bind parameters for markers */
$stmt->bind_param('s', $username);
/* execute query */
if($stmt->execute()){
/* store result */
$stmt->store_result();
if($stmt->num_rows > 0){
/* bind result variables */
$stmt->bind_result($username_tmp, $password_hash);
/* fetch value */
$stmt->fetch();
if(password_verify ($password, $password_hash)){
echo "Success" . "|" . $username_tmp . ;
return;
}else{
$errors[] = "Wrong username or password.";
}
}else{
$errors[] = "Wrong username or password.";
}
/* close statement */
$stmt->close();
}else{
$errors[] = "Something went wrong, please try again.";
}
}else{
$errors[] = "Something went wrong, please try again.";
}
if(count($errors) > 0){
echo $errors[0];
}
}else{
echo "Missing data";
}
?>