Use bcrypt for login form. Add tests to check that salts and hashes are random, and check handling of invalid passwords or salts.

This commit is contained in:
James Valleroy authored and Nick Daly committed 2013-11-11 07:28:26 -06:00
1 parent 8ba1d318ec
commit 4a9177a257
2 files changed
+73 -2

No files matched your search

+3 -2
View File
@@ -7,7 +7,8 @@
# on 1 February 2011.
import cherrypy
import urllib, hashlib
import urllib
from passlib.hash import bcrypt
import cfg
import random
import time
@@ -31,7 +32,7 @@ def check_credentials(username, passphrase):
u = None
# hash the password whether the user exists, to foil timing
# side-channel attacks
pass_hash = hashlib.md5(passphrase).hexdigest()
pass_hash = bcrypt.encrypt(passphrase, salt=u['salt'])
if u is None or u['passphrase'] != pass_hash:
error = "Bad user-name or password."