1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- def wordpress_passwd(password, salt, count, prefix, uppercase=False):
- """
- Reference(s):
- http://packetstormsecurity.org/files/74448/phpassbrute.py.txt
- http://scriptserver.mainframe8.com/wordpress_password_hasher.php
- >>> wordpress_passwd(password='testpass', salt='aD9ZLmkp', count=2048, prefix='$P$9aD9ZLmkp', uppercase=False)
- '$P$9aD9ZLmkpsN4A83G8MefaaP888gVKX0'
- """
- def _encode64(input_, count):
- output = ''
- i = 0
- while i < count:
- value = ord(input_[i])
- i += 1
- output = output + ITOA64[value & 0x3f]
- if i < count:
- value = value | (ord(input_[i]) << 8)
- output = output + ITOA64[(value >> 6) & 0x3f]
- i += 1
- if i >= count:
- break
- if i < count:
- value = value | (ord(input_[i]) << 16)
- output = output + ITOA64[(value >> 12) & 0x3f]
- i += 1
- if i >= count:
- break
- output = output + ITOA64[(value >> 18) & 0x3f]
- return output
- if isinstance(password, unicode):
- password = password.encode(UNICODE_ENCODING)
- cipher = md5(salt)
- cipher.update(password)
- hash_ = cipher.digest()
- for i in xrange(count):
- _ = md5(hash_)
- _.update(password)
- hash_ = _.digest()
- retVal = prefix + _encode64(hash_, 16)
- return retVal.upper() if uppercase else retVal
|