brian herman wrote:

 > I have a python application that uses pysimplesoap to send a soap request to 
 > windows.
 > The problem is the password field is not encoded in UTF-8 it may use 
 > Windows-1252?
 > Python Code
 > https://gist.github.com/brianherman/209af7751444ec308e1b
 > Visual Basic Sample code (how to encode the password field in visual basic)
 > https://gist.github.com/brianherman/b4174b99be9000fcc4f8
 > They use visual basic to encode the password which works. The problem is 
 > reproducing this in
 > python
 > This is the encoded password in the database (microsoft sql server):
 > [...]
 > I have tried using the md5 package in python but I can't seem to get the 
 > encoding right.
 
The VB code is strange. It uses ASCIIEncoding which only supports 7-bit codes. 
But the MD5 hash generates 8-bit codes and with the conversion to ASCII any 
code > 127 will be replaced by a question mark. You see that in the value in 
the databes where about half the characters are question marks. Or maybe they 
made the same error in the server, so that the passwords DO match. 

The Python code (supposing Python 2) normally would be:

import hashlib
m = hashlib.md5(password)
print m.digest()

However, if my guess is right that the characters > 127 must be replaced by 
question marks, the following should do it:

import hashlib
m = hashlib.md5(password)
pw = "".join(c if c < chr(128) else '?' for c in m.digest())
print pw

-- 
Piet van Oostrum <[email protected]>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
_______________________________________________
Soap mailing list
[email protected]
https://mail.python.org/mailman/listinfo/soap

Reply via email to