-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.php
More file actions
90 lines (73 loc) · 1.83 KB
/
form.php
File metadata and controls
90 lines (73 loc) · 1.83 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
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
<?php
//comments
#comments
/* comments
comments
comments */
include_once("functions.php");
include_once("validations.php");
$errors = array();
include_once("header.php");
$userHash="123";
$message="";
$userDB="12345678";
$passDB="12345678";
$min=array("username"=>8, "password" =>6);
$max=array("username"=>16,"password" =>12);
if(isset($_POST['submit']))
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$fields= array("username","password");
foreach($fields as $field)
{
$check = $_POST[$field];
if(!checkValid($check))
{
$errors[$field]="{$field} can't be empty.";
}
else
{
if(!checkMax($check,$max[$field]))
{
$errors[$field]="{$field} can't be more than {$max[$field]} characters.";
}
if(!checkMin($check,$min[$field]))
{
$errors[$field]="{$field} can't be less than {$min[$field]} characters.";
}
}
}
if(empty($errors))
{
if($username == $userDB && $password == $passDB)
{
redirectTo("form.php");
}
else
{
$message = "Username and Password do not match";
}
}
else
{
echo checkErrors($errors);
}
}
else
{
$username = "";
$password = "";
$message = "Please log in.";
}
?>
<body>
<?php echo $message; ?>
<form action="form.php" method="post">
Username: <input type="text" name="username" value="<?php echo htmlspecialchars($username);?>"/><br />
Password: <input type="password" name="password" value=""/><br />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>