Skip to content

use bcrypt #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gevent==0.13.7
py-bcrypt==0.2
10 changes: 9 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@


def mangodb(socket, address):
if os.environ.get('MANGODB_USE_BCRYPT', False):
import bcrypt
else:
bcrypt = None

socket.sendall('HELLO\r\n')
client = socket.makefile()
output = open('/dev/null', 'w')
Expand All @@ -19,7 +24,10 @@ def mangodb(socket, address):
if os.environ.get('MANGODB_DURABLE', False):
output.flush()
os.fsync(output.fileno())
client.write('OK' + os.urandom(1024).encode('string-escape') + '\r\n')
data = os.urandom(1024)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably go all the way up to 4096. And just pick ALL CAPS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thekad Why didn't you share this project with the grit guys?

if os.environ.get('MANGODB_USE_BCRYPT', False):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be changed to if bcrypt: ? feels more pythonic

data = bcrypt.hashpw(data.encode('string-escape'), bcrypt.gensalt())
client.write('OK' + data.encode('string-escape') + '\r\n')
client.flush()


Expand Down