Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using AJAX for form #9

Open
wants to merge 4 commits into
base: hacktober
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# hashr
### _Password hash generator_

List of all PHP hashing algorithms ([hash_algos() function](http://php.net/manual/en/function.hash-algos.php)) and their result for an input string.
List of all PHP hashing algorithms ([hash_algos() function](http://php.net/manual/en/function.hash-algos.php)) and their result (and hashing time) for an input string.
10 changes: 10 additions & 0 deletions calculate_hashes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
require("function.php");
foreach (hash_algos() as $i => $algo) {
?>
<div class="hash_algo">
<p class="algo"><b><?= $algo; ?></b></p>
<p>Hash: <span style="font-family: Nunito"><?= $hashes[$i]; ?></span></p>
<small>Execution time: <?= number_format($hashTime[$algo] * 1000000000, 0); ?> nanoseconds</small>
</div>
<?php } ?>
9 changes: 7 additions & 2 deletions function.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php
$hashes = array();
if(isset($_POST['submit']) && !empty($_POST['input'])){
$hashTime = array();
if(isset($_POST['input']) && !empty($_POST['input'])){
foreach (hash_algos() as $algo) {
array_push($hashes, hash($algo, $_POST['input']));
$start = microtime(true);
$hash = hash($algo, $_POST['input']);
$timeElapsed = microtime(true) - $start;
$hashTime[$algo] = $timeElapsed;
array_push($hashes, $hash);
}
}
?>
30 changes: 16 additions & 14 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?php
require_once("function.php");
?>
<!DOCTYPE html>
<html>
<head>
Expand All @@ -17,24 +14,29 @@
grid-auto-columns: minmax(20%, 30%);
}
</style>
<script>
$(document).ready(function(){
$("#hashForm").submit(function(e){
e.preventDefault();
$.post("calculate_hashes.php", {
input: $("#text").val()
}, function(response){
$("#hashes").html(response);
});
});
});
</script>
<link href="https://fonts.googleapis.com/css?family=Nunito|Orbitron" rel="stylesheet">
</head>
<body>
<form method="post">
<form method="get" id="hashForm">
<label>Input string: </label>
<input type="text" name="input">
<input type="text" name="input" id="text">
<input type="submit" name="submit" value="Hash!">
</form>
<br>
<div class="hashes">
<?php
foreach (hash_algos() as $i => $algo) { ?>
<div class="hash_algo">
<p class="algo"><b><?= $algo; ?></b></p>
<p>Hash: <span style="font-family: Nunito"><?= $hashes[$i]; ?></span></p>
</div>
<?php }
?>
<div class="hashes" id="hashes">

</div>
</body>
</html>
Expand Down