My wordpress backend is using phpass hash algorithm and giving me phpass using web service. In ios end in swift I am trying to generate same phpass hash in swift. Below are codes in swift and php. Both have same input but output is different. So question is that how can i get same output. Am I missing anything?
Php code :
<?php
function phpassHash($password, $salt,$iterations){
$hash = hash('md5', $salt.$password, TRUE);
for($i = 0; $i < $iterations; $i++){
$hash = hash('md5', $hash.$password, TRUE);
}
return $hash;
}
$result = phpassHash("a_test_password","MsdvACyA", 8192);
echo bin2hex($result);
?>
Swift code :
func md5(string: String) -> String {
var digest = [UInt8](count: Int(CC_MD5_DIGEST_LENGTH), repeatedValue: 0)
if let data = string.dataUsingEncoding(NSUTF8StringEncoding) {
CC_MD5(data.bytes, CC_LONG(data.length), &digest)
}
var digestHex = ""
for index in 0..<Int(CC_MD5_DIGEST_LENGTH) {
digestHex += String(format: "%02x", digest[index])
}
return digestHex
}
func phpassHash(password: String, salt: String, iterations: Int) -> String {
var hash = md5(salt+password)
for _ in 0..<iterations {
hash = md5(hash+password)
}
return hash;
}