Created
June 17, 2011 03:23
-
-
Save averyaube/1030810 to your computer and use it in GitHub Desktop.
Bonafide Mechanism for basic Magento passwords
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed to import users from an existing Magento site to a Kohana app using Bonafide. Made it really easy!