Skip to content

Instantly share code, notes, and snippets.

@averyaube
Created June 17, 2011 03:23
Show Gist options
  • Save averyaube/1030810 to your computer and use it in GitHub Desktop.
Save averyaube/1030810 to your computer and use it in GitHub Desktop.
Bonafide Mechanism for basic Magento passwords
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Basically just an MD5 hash with 1 iteration, and then the salt attached at the end.
*
* @author Lowgain
*/
class Bonafide_Mechanism_Magento extends Bonafide_Mechanism {
public function check($password, $hash, $salt = NULL, $iterations = NULL)
{
// For Magento, the salt is at the end of the hash
$salt = substr($hash, strpos($hash, ':') + 1);
return parent::check($password, $hash, $salt, 1);
}
public function hash($password, $salt = NULL, $iterations = NULL)
{
// Hash the password, only one iteration supported
return parent::hash($password, $salt, 1);
}
protected function _hash($input, $salt = NULL)
{
// Starts off as this
$pass = md5($salt . $input);
// Add the salt to the end if its there
if ($salt !== NULL)
{
$pass .= ':' . $salt;
}
return $pass;
}
}// End Bonafide_Mechanism_Magento
@averyaube
Copy link
Author

I needed to import users from an existing Magento site to a Kohana app using Bonafide. Made it really easy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment