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

Added client side form validation #10

Open
wants to merge 19 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 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.


#### The app is deployed on heroku: [Hashr](https://hashr-php.herokuapp.com/)
8 changes: 7 additions & 1 deletion function.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php
$hashes = array();
$hashTime = array();
if(isset($_POST['submit']) && !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;
$hashes[$algo] = $hash;
}
}
?>
29 changes: 9 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
<?php
<?php
require_once("function.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Hashr</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<style type="text/css">
html{
font-family: Orbitron;
}
.hashes {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 10px;
grid-auto-columns: minmax(20%, 30%);
}
</style>
<link href="main.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito|Orbitron" rel="stylesheet">
</head>
<body>
<form method="post">
<form name ="hashform" method="post" onsubmit="return validateform()">
<label>Input string: </label>
<input type="text" name="input">
<input type="submit" name="submit" value="Hash!">
<input type="text" name="input" required oninvalid="this.setCustomValidity('You can\'t leave the input string blank!')">
<input type="submit" class="submit" name="submit" value="Hash!">
</form>
<br>
<div class="hashes">
<?php
foreach (hash_algos() as $i => $algo) { ?>
<?php
foreach (hash_algos() as $algo) { ?>
<div class="hash_algo">
<p class="algo"><b><?= $algo; ?></b></p>
<p>Hash: <span style="font-family: Nunito"><?= $hashes[$i]; ?></span></p>
<p class="hash">Hash: <span style="font-family: Nunito"><?= $hashes[$algo]; ?></span></p>
<small>Execution time: <span class="exec-time" style="font-family: Nunito"><?= number_format($hashTime[$algo] * 1000000000, 0); ?> nanoseconds</span></small>
</div>
<?php }
?>
</div>
</body>
</html>


65 changes: 65 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
html{
font-family: Orbitron;
background: black;
color: #1be71b;
}
.hashes {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 12px;
}

.hash_algo{
border: 0.6px solid rgb(44, 140, 49);
padding: 10px;
}

.algo{
font-size: 19px;
}

.hash{
font-size: 15px;
}

.exec-time{
font-weight: bold;
}

.submit{
background-color: green;
border: 2px solid green;
color: #fff;
width: 100px;
margin-left: 20px;
font-family: Orbitron;
-webkit-transition: all 0.5s ease-in;
-moz-transition: all 0.5s ease-in;
-ms-transition: all 0.5s ease-in;
-o-transition: all 0.5s ease-in;
transition: all 0.5s ease-in;

}

.submit:hover{
cursor: pointer;
font-size: 15px;
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
-webkit-transition: all 0.5s ease-in;
-moz-transition: all 0.5s ease-in;
-ms-transition: all 0.5s ease-in;
-o-transition: all 0.5s ease-in;
transition: all 0.5s ease-in;
}

small{
font-size: 12px;
}

p{
margin: 10px 0;
}