Skip to content

Commit

Permalink
Add password check on authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
leportella committed Jan 9, 2019
1 parent cd2c756 commit 03c8f29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nativeauthenticator/nativeauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def __init__(self, *args, **kwargs):

@gen.coroutine
def authenticate(self, handler, data):
return data['username']
user = UserInfo.find(self.db, data['username'])
if user.is_valid_password(data['password']):
return data['username']

def get_or_create_user(self, username, password):
user = User.find(self.db, username)
Expand Down
5 changes: 5 additions & 0 deletions nativeauthenticator/orm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bcrypt
from sqlalchemy import (
Column, Integer, String
)
Expand All @@ -18,3 +19,7 @@ def find(cls, db, username):
Returns None if not found.
"""
return db.query(cls).filter(cls.username == username).first()

def is_valid_password(self, password):
encoded_pw = bcrypt.hashpw(password.encode(), self.password)
return encoded_pw == self.password

0 comments on commit 03c8f29

Please sign in to comment.