Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions visualcaptcha/Captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import random
import mimetypes
import binascii


class Captcha(object):
Expand Down Expand Up @@ -198,7 +199,11 @@ def getAllAudioOptions(self):

# Create a hex string from random bytes
def utilRandomHex(self, count):
return os.urandom(count).encode('hex')
return str(binascii.hexlify(os.urandom(count)))

# Create a hex string from random bytes
def utilRandomHexBytes(self, count):
return binascii.hexlify(os.urandom(count))

# Read input file as JSON
def utilReadJSON(self, filePath):
Expand Down Expand Up @@ -226,12 +231,12 @@ def utilStreamFile(self, headers, filePath):
headers['Pragma'] = 'no-cache'
headers['Expires'] = 0

f = open(filePath)
f = open(filePath, 'rb')
content = f.read()
f.close()

# Add some noise randomly, so images can't be saved and matched easily by filesize or checksum
content += self.utilRandomHex( random.randint(0, 1500) )
content += self.utilRandomHexBytes( random.randint(0, 1500) )

return content

Expand Down
4 changes: 2 additions & 2 deletions visualcaptcha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
from Session import *
from Captcha import *
from .Session import *
from .Captcha import *