Skip to content

Instantly share code, notes, and snippets.

Last active April 1, 2017 19:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tpkemme/7965fe309cb6810a5dfcb348ebf1dc3a to your computer and use it in GitHub Desktop.
Wordpress hash password and return results - Alfred Workflow
* This php script queries a form at
* to get a
* hashed version of a provided or default password
* This script is run using the command 'wpash <password>'. If the command is run without
* any parameters it will return the hash of the string 'password'. If a parameter is provided
* (example: 'wpash P@s$w0rD'), this script will return the hash of the string 'P@s$w0rD'
* This can be used in an Alfred Workflow to hash passwords for Wordpress sites. A great tool
* for developers who manage databases for a lot of Wordpress sites
// Query in the form of one parameter 'password' to hash
$query = "{query}";
$password = '';
// There are no arguments...
if( empty( $query ) ){
// No provided password, use default 'password'
$password = 'password';
// At least 1 argument exists
// Turn query string into params array
$params = explode(' ', $query);
// Get provided password (use first param, ignore others)
$password = $params[0];
// Url of password hashing tool for wordpress
$hashUrl = '';
$data = array('phrase' => $password);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data))
$context = stream_context_create($options);
$output = file_get_contents( $hashUrl, false, $context );
// Extract hash
$first_step = explode( '<strong>' , $output );
$second_step = explode('</strong>' , $first_step[1] );
echo $second_step[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment