-
Notifications
You must be signed in to change notification settings - Fork 1
/
form_demo.php
79 lines (66 loc) · 1.58 KB
/
form_demo.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
<?php
session_start(); // Called before loading the class!
require_once 'class_csrf.php';
if (isset($_POST['submit']))
{
$username = trim(strip_tags($_POST['username']));
$password = trim(strip_tags($_POST['password']));
$errors = array();
$messages = array();
if (Token::isValid() AND Token::isRecent())
{
if (empty($username))
{
$errors[] = 'Username cannot be blank.';
}
if (empty($password))
{
$errors[] = 'Password cannot be blank.';
}
$messages[] = 'Security Token was valid.';
}
else
{
// Invalid security token
$errors[] = 'Invalid Security Token';
// You could use the exitOnFailure method or handle it your own way.
}
}
?>
<!doctype html>
<html>
<head>
<title>CSRF Class Form Demo</title>
</head>
<body>
<h2>CSRF Class Form Demo</h2>
<?php
if (@$errors)
{
foreach ($errors as $error)
{
echo '<span style="color: red;">' . $error . '</span><br />';
}
echo '<br />';
}
if (@$messages)
{
foreach ($messages as $message)
{
echo '<span style="color: green;">' . $message . '</span><br />';
}
echo '<br />';
}
?>
<form action="" method="post" autocomplete="off">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required />
<br />
<label for="password">Password:</label>
<input type="password" name="password" id="password" required />
<!-- Comment this out for an "invalid security token" example. -->
<?php echo Token::display(); ?><br /><br />
<input type="submit" name="submit" value="Login" />
</form>
</body>
</html>