-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
60 lines (56 loc) · 1.63 KB
/
Copy pathindex.php
File metadata and controls
60 lines (56 loc) · 1.63 KB
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
<form action="" method="post" name="Login_Form">
<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table">
<?php if(isset($msg)){?>
<tr>
<td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" align="left" valign="top"><h3>Signup and Login FORM</h3></td>
</tr>
<tr>
<td align="right" valign="top">Username</td>
<td><input name="Username" type="text" class="Input"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input name="Password" type="password" class="Input"></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="register/Login" class="Button3"></td>
</tr>
</table>
</form>
<?php
require_once "config.php";
if($_SERVER["REQUEST_METHOD"]=="POST"){
#chech if the fields not empty agaian for more validation...:)
if (isset($_POST["Submit"])){
$username=$_POST["Username"];
$password=$_POST["Password"];
$options=[
"cost"=>12
];
// instead of the database in this version
$logins=[
"ali"=>password_hash("ali123",PASSWORD_BCRYPT,$options),
"rita"=>password_hash("rita123",PASSWORD_BCRYPT,$options)
];
if (isset($logins[$username])&& password_verify($password,$logins[$username])){
$_SESSION["UserId"]=$username;
header("Location:dashboard.php");
exit;
}
else
{
header("Location:index.php");
}
}
}
if(isset($_SESSION["UserId"])){
header("Location: dashboard.php");
}
?>
<!-- https://medium.com/@patelharsh7458/php-sessions-explained-practical-usage-and-best-practices-b15df9cc7568 -->
<!-- https://www.phparch.com/2018/01/php-sessions-in-depth/ -->