-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhashing.php
183 lines (164 loc) · 6.55 KB
/
hashing.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
require_once 'init.php';
session_start();
if (!isset($_SESSION['username'])) {
header('Location: login.php');
}
$username = $_SESSION['username'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input = filter_input(INPUT_POST, "hash", FILTER_SANITIZE_SPECIAL_CHARS);
if (!empty($input)) {
$type = $_POST["ans"];
if ($type == "md2") {
$opposite = hash("md2", $input);
} else if ($type == "md4") {
$opposite = hash("md4", $input);
} else if ($type == "md5") {
$opposite = hash("md5", $input);
} else if ($type == "sha1") {
$opposite = hash("sha1", $input);
} else if ($type == "sha256") {
$opposite = hash("sha256", $input);
} else if ($type == "sha512") {
$opposite = hash("sha512", $input);
} else if ($type == "ripemd128") {
$opposite = hash("ripemd128", $input);
} else if ($type == "ripemd256") {
$opposite = hash("ripemd256", $input);
} else if ($type == "whirlpool") {
$opposite = hash("whirlpool", $input);
} else if ($type == "snefru") {
$opposite = hash("snefru", $input);
} else if ($type == "crc32") {
$opposite = hash("crc32", $input);
} else {
$opposite = hash("adler32", $input);
}
$display = "<div style='color: #00008B'><h2>Hash:</h2><br> <h2>$opposite</h2></div>";
//PUT LOGIC HERE FOR HASHING
try {
global $connect;
$sql = "INSERT INTO hashing (username, algorithm, original, opposite, date)
VALUES(:username, :algo, :input, :opposite, current_timestamp)";
$stmt = $connect->prepare($sql);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':algo', $type);
$stmt->bindParam(':input', $input);
$stmt->bindParam(':opposite', $opposite);
$stmt->execute();
} catch (exception $e) {
$display = "Error: " . $e->getMessage();
}
} else {
$display = "<div style='color: #00008B'><h2>Fatal Error.. Please retry</h2></div>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Consolidev | Hashing</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="CSS/styles.css">
<link rel="stylesheet" href="CSS/hashing.css">
<script src="https://kit.fontawesome.com/d0af7889fc.js" crossorigin="anonymous"></script>
</head>
<body>
<?php include 'header.php'; ?>
<main>
<div class="container">
<div class="tool-title">
<i class="fa-solid fa-hashtag"></i>
<h1>Hashing Tool</h1>
</div>
<div class="form">
<form action="hashing.php" method="post">
<label for="hash">Enter a value and choose hashing algorithm:</label>
<br>
<div class="radio-group">
<div class="radio-column">
<div class="radio-option">
<input type="radio" id="md2" name="ans" value="md2" required>
<label for="md2">MD-2</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="md4" name="ans" value="md4" required>
<label for="md4">MD-4</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="md5" name="ans" value="md5" required>
<label for="md5">MD-5</label>
</div>
</div>
<div class="radio-column">
<div class="radio-option">
<input type="radio" id="sha1" name="ans" value="sha1" required>
<label for="sha1">SHA-1</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="sha256" name="ans" value="sha256" required>
<label for="sha256">SHA-256</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="sha512" name="ans" value="sha512" required>
<label for="sha512">SHA-512</label>
</div>
</div>
<div class="radio-column">
<div class="radio-option">
<input type="radio" id="ripemd128" name="ans" value="ripemd128" required>
<label for="ripemd128">Ripemd-128</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="ripemd256" name="ans" value="ripemd256" required>
<label for="ripemd256">Ripemd-256</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="whirlpool" name="ans" value="whirlpool" required>
<label for="whirlpool">Whirlpool</label>
</div>
</div>
<div class="radio-column">
<div class="radio-option">
<input type="radio" id="snefru" name="ans" value="snefru" required>
<label for="snefru">Snefru</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="crc32" name="ans" value="crc32" required>
<label for="crc32">CRC-32</label>
</div>
<br>
<div class="radio-option">
<input type="radio" id="adler32" name="ans" value="adler32" required>
<label for="adler32">Adler32</label>
</div>
</div>
</div>
<input class="hash-input" type="text" id="hash" name="hash" placeholder="Type here" required><br><br>
<input type="submit" value="Hash">
</form>
</div>
<div class="form hash-history">
<a href="hashingHistory.php">
<button class="history-btn" style="width:auto">View History</button>
</a>
<?php
if (!empty($display)) {
echo $display;
}
?>
</div>
</div>
</main>
<footer>
<p>© <span id="2024"></span> consoliDev. All Rights Reserved.</p>
</footer>
</body>
</html>