Created
July 20, 2017 18:00
-
-
Save ehedaya/288c7280ee76b436cceec15941e4093a to your computer and use it in GitHub Desktop.
PHP script to hash email addresses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$emails = $_POST['emails']; | |
if($emails) { | |
$lines = split("\n", $emails); | |
$output = array(); | |
foreach($lines as $line) { | |
$normalized = trim(strtolower($line)); | |
$crypto = $_POST['crypto']; | |
if(!$crypto || $crypto == "md5") { | |
$hash = md5($normalized); | |
} else if ($crypto == "sha1") { | |
$hash = sha1($normalized); | |
} else if ($crypto == "sha256") { | |
$hash = hash('sha256',$normalized); | |
} | |
if(strlen($normalized) > 0) { | |
$output[] = array("input" => trim($line), "normalized" => $normalized, "modified" => trim($line) !== $normalized , "output" => $hash); | |
} | |
} | |
} | |
if($output && $_POST["format"] === "json") { | |
header('Content-Type: text/json'); | |
print_r(json_encode($output)); | |
exit; | |
} else if ($output && $_POST["format"] === "txt") { | |
header('Content-Type: text/plain'); | |
foreach($output as $line) { | |
echo $line["output"] . "\n"; | |
} | |
exit; | |
} else if ($output && $_POST["format"] === "tsv") { | |
header('Content-Type: text/plain'); | |
echo "Input\tNormalized\tHash\n"; | |
foreach($output as $line) { | |
echo $line["input"] . "\t" . $line["normalized"] . "\t" . $line["output"] . "\n"; | |
} | |
exit; | |
} | |
?> | |
<form method="POST"> | |
<fieldset> | |
<legend>Input</legend> | |
<textarea name="emails" rows="5"><?php echo $_POST['emails']?></textarea><br/> | |
</fieldset> | |
<fieldset> | |
<legend>Hash type</legend> | |
<label><input type="radio" name="crypto" value="md5"> MD5 (default)</label> | |
<label><input type="radio" name="crypto" value="sha1"> SHA1</label> | |
<label><input type="radio" name="crypto" value="sha256"> SHA256</label> | |
</fieldset> | |
<fieldset> | |
<legend>Output format</legend> | |
<label><input type="radio" name="format" value="html" /> HTML Table (default)</label><br/> | |
<label><input type="radio" name="format" value="json" /> JSON</label><br/> | |
<label><input type="radio" name="format" value="tsv" /> TSV</label><br/> | |
<label><input type="radio" name="format" value="txt" /> Plain text (hashes only)</label><br/> | |
</fieldset> | |
<button type="submit">Submit</button> | |
</form> | |
</fieldset> | |
<?php if($output) { ?> | |
<hr/> | |
<table> | |
<thead> | |
<tr> | |
<td>Input</td> | |
<td>Normalized</td> | |
<td>Hash</td> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach($output as $line) { ?> | |
<tr> | |
<td><?php echo $line["input"]; ?></td> | |
<td><?php if($line["modified"]) { echo $line["normalized"]; } ?></td> | |
<td><?php echo $line["output"]; ?></td> | |
</tr> | |
<?php } ?> | |
</tbody> | |
</table> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment