-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
159 lines (154 loc) · 6.38 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
session_start();
if(isset($_SESSION['username']))
{
header("location: home.php");
die();
}
?>
<?php
include 'conn.php';
$login = false;
$userCheck = $passCheck = false;
$userError = $passError = false;
if(isset($_POST['submit']))
{
$username = $_POST["username"];
$pass = $_POST["pass"];
// Username input validation
if(empty($username)) {
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Warning! </strong>Username cannot be empty.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
</div>";
$userError = true;
}
else if(preg_match("/^[A-Za-z0-9!@#$%^&*_.]{3,}$/",$username)) {
$userCheck = true;
}
else{
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Warning! </strong>Invalid Username.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
</div>";
$userError = true;
}
// Password input validation
if(empty($pass)) {
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Warning! </strong>Password cannot be empty.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
</div>";
$passError = true;
}
else if(preg_match('/^[A-Za-z0-9!@#$%^&*_.]{1,}$/', $pass)) {
$passCheck = true;
}
else{
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Warning! </strong>Trying to Hack me. Not that much EASY :)
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
</div>";
$passError = true;
}
if($userCheck && $passCheck)
{
$sql = "SELECT * FROM `login` WHERE `username` LIKE '$username' AND `pass` LIKE '$pass'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$check = mysqli_num_rows($result);
if($check >= 1)
{
$login = true;
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username'] = strtolower($username);
$_SESSION['mobile'] = $row['mobile'];
$_SESSION['email'] = $row['email'];
$_SESSION['pass'] = $row['pass'];
$_SESSION['timestamp'] = time();
header("location: home.php");
}
else
{
$userError = $passError = true;
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Warning! </strong>Either Username or Password is incorrect.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
</div>";
}
}
}
else{
$username = $pass = NULL;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/index.css">
<title>Sign In | Namaste</title>
<link rel="icon" href="img/n.jpg" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<style>
* {
font-family: 'Poppins', sans-serif;
}
h1,h2,h3,h4,h5,h6{
font-weight: bold;
}
.fa-exclamation-circle{
position: absolute;
margin-top: 15px;
margin-left: 3px;
font-size: 15px;
color: orange;
}
</style>
</head>
<body>
<div class="cont">
<div class="demo">
<div class="login">
<div class="login__check">
<img src="img/n.jpg" alt="user">
</div>
<div class="login__form">
<form method="POST">
<div class="login__row">
<svg class="login__icon name svg-icon" viewBox="0 0 20 20">
<path d="M0,20 a10,8 0 0,1 20,0z M10,0 a4,4 0 0,1 0,8 a4,4 0 0,1 0,-8" />
</svg>
<input type="text" name="username" class="login__input name" value="<?php echo $username; ?>" placeholder="Username"/>
<?php if($userError) echo "<i class='fa fa-exclamation-circle' aria-hidden='true'></i>"; ?>
</div>
<div class="login__row">
<svg class="login__icon pass svg-icon" viewBox="0 0 20 20">
<path d="M0,20 20,20 20,8 0,8z M10,13 10,16z M4,8 a6,8 0 0,1 12,0" />
</svg>
<input type="password" name="pass" class="login__input pass" value="<?php echo $pass; ?>" placeholder="Password"/>
<?php if($passError) echo "<i class='fa fa-exclamation-circle' aria-hidden='true'></i>"; ?>
</div>
<input type="submit" name="submit" class="login__submit" value="Sign In">
<p class="login__signup">Don't have an account? <a href="signup.php">Sign Up</a></p>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<script>
$('.alert').alert()
</script>