-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
50 lines (38 loc) · 1012 Bytes
/
login.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
<?php
include_once('connect.php');
session_start();
$flag = 0;
$db_username = null;
$db_password = null;
$db_id = null;
if(isset($_POST['login'])){
$username = $_POST['usernamelogin'];
$username = $connection->real_escape_string($username);
$password = $_POST['passwordlogin'];
$hashFormat = "$2y$10$";
$salt = "notedoisawesomeuseitnow";
$hashAndSalt = $hashFormat . $salt;
$password = crypt($password, $hashAndSalt);
$query = "SELECT * FROM users ";
$result = $connection->query($query);
while($row = $result->fetch_assoc()){
$db_username = $row['username'];
$db_password = $row['password'];
$db_id = $row['id'];
if($username == $db_username && $password == $db_password){
$flag = 1;
break;
}
}
if($flag == 1){
$flag = 0;
$_SESSION['curr_id'] = $db_id;
$_SESSION['curr_username'] = $db_username;
header("Location: usernotes.php");
}
else{
$_SESSION['info_l'] = 'Wrong Credentials';
header("Location: index.php#tologin");
}
}
?>