Skip to content
Advertisement

Python is Garbling a Salt Generated from PHP and Stored in Mysql

I am exporting, by scraping it with http requests since the host won’t give me database access, a forum and importing it into a mysql database for vbulletin.

In vbulletin users have unique password salts, and it generates password hashes using this algorithm:

JavaScript

I’m using a python script to read stored data from my sqlite database of user information to generate a new password and salt for users, then storing that data into the mysql database so vbulletin can use it.

My problem is that python is changing the value of strings in unexpected ways. I’m testing my script using a known password and salt to compare the hashes. However, the salt that I’m using is this:

JavaScript

When I try to store that in python, when I retrieve the string I get this:

JavaScript

This is the python code I’m using to mimic the vbulletin hashing algorithm:

JavaScript

For comparison, this PHP matches what vbulletin stores as the password hash in the database:

JavaScript

$hash matches what vbulletin stores and password_hash does not. What am I doing wrong to cause the difference?

Advertisement

Answer

The way you’re defining salt is the problem. You have to either make it a raw string:

JavaScript

Or escape the backslashes:

JavaScript

Otherwise, 3 is interpreted as the escape sequence for the character with a character code of 3.

Also, for readability, you may want to make an md5 function:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement