This is the original generator as found in the Creating a LXD Backup Server post, I have decided to give it a nice home of it’s own. It is still in the original post along with the source easily copied for your use, abuse and pleasure.
Password Generator by Dave Wise
© Dave Wise 2022 . use and abuse . feel free to credit
For anyone creating anything to do with passwords and php then invariably they will need to generate fallback hashes to get them out of trouble, well instead of having to write one, this generates a hash using <?php password_hash(‘<password>’, PASSWORD_DEFAULT ); ?> and lets you copy it until your hearts content.
A password_hash Generator
by Dave Wise
This uses PASSWORD_DEFAULT as the hash generator
© Dave Wise 2022 . use and abuse . feel free to credit
If anyone is interested about the hash thing above, it’s proper simple, the only complicated bit was getting wordpress to do its thing with ajax calls.
To start, I created a simple plugin that created an AJAX action that then returned the hash of the requested data to be hashed. Then created an empty javascript to queue, added a javascript var for the ajax url and that’s pretty much it. Well, I had to activate the plugin obviously. I didn’t go to town, I just wanted it to work.
All delivered using Custom HTML blocks and given to you using Code Pro blocks.
If it helps, all power to you … if it doesn’t … ah well, I tried #peaceout.
<?php
/*
Plugin Name: Hash Generator
Description: A hash generator that uses password_hash() but allows access to the front end for people needing static hashes
Author: Dave Wise
Version: 0.1
*/
function get_hash() {
$pass = $_POST['passwordInput'];
echo password_hash($pass, PASSWORD_DEFAULT);
wp_die();
}
add_action ( 'wp_ajax_nopriv_get_hash', 'get_hash' );
add_action ( 'wp_ajax_get_hash', 'get_hash' );
wp_register_script( 'hashGenScript', '');
wp_enqueue_script( 'hashGenScript' );
wp_add_inline_script( 'hashGenScript',
'const hashGenVar = ' . json_encode( array ( 'ajaxURL' => admin_url('admin-ajax.php') )) . ';'
);
?>
<script>
function getHash() {
const password = document.getElementById("passwordInput").value;
if (password == "") alert('Text input cannot be empty you plank');
else {
var formData = new FormData();
formData.append("action", "get_hash");
formData.append("password", password);
jQuery.ajax({
type: "POST",
url: hashGenVar.ajaxURL,
data: formData,
cache: false,
processData: false,
contentType: false,
success: function(newHash) {
var hashBox = document.getElementById("hashBox");
hashBox.innerText = newHash;
}
});
}
}
function copyHash() {
const textarea = document.createElement('textarea');
const password = document.getElementById("hashBox").innerText;
if (!password) { return; }
textarea.value = password;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
textarea.remove();
alert('Password copied to clipboard');
}
</script>
<div style='background: #C1E1C1; color: white; max-width: 60%; margin: 0 auto; font-family: -apple-system, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important; margin: 10px 0 20px 0;'>
<div style="padding: 30px !important">
<h3 style="color: #417141" >A password_hash Generator <br /> by Dave Wise</h3>
<p>This uses PASSWORD_DEFAULT as the hash generator</p>
<input style="border: 1px solid #417141; border-radius: 5px; padding: 15px; outline: none; background: transparent;" type="text" name="passwordInput" id="passwordInput" placeholder="Enter the text to Hash"/>
<div style="display: flex; align-items: center; justify-items: left; width: 100%; margin-bottom: 15px;">
<p id="hashBox" style="overflow: hidden; padding: 10px 15px; border: 2px solid #f9f9f9; border-radius: 15px; font-size: 1.6rem; min-width: 50%; width: 90%;"> </p>
<span onclick="copyHash()" style="font-size: 1.6rem; font-weight: bold; cursor: pointer;" class="dashicons dashicons-clipboard"></span>
</div>
<div style="display: flex; align-items: center; justify-items: left;" >
<button style="width:60%; padding: 10px 15px; margin-left: 10px; border-radius: 10px; background: #417141; color: #ffffff; border: 0; outline: none; cursor: pointer" onclick="getHash()">Get Password Hash</button>
</div>
<p>© Dave Wise 2024 . use and abuse . feel free to credit</p>
</div>
</div>
Leave a Reply