1
我運行一個GQLQuery查找,如果用戶輸入正確的憑據:GQLQuery檢索空結果集
class User(db.Model):
UserName = db.TextProperty();
Password = db.TextProperty();
Ticket = db.TextProperty();
class Authentication(webapp.RequestHandler):
def post(self):
str_user = self.request.get('user')
str_password = self.request.get('password')
user = db.GqlQuery("SELECT * FROM User WHERE UserName = :1 AND Password = :2",str_user, str_password)
self.response.out.write(str_user)
self.response.out.write(str_password)
self.response.out.write(str([u.UserName for u in user]))
if user.count() > 0:
ticket = str(uuid.uuid4())
user.Ticket = ticket
self.response.out.write(ticket)
else:
self.response.out.write('Not authorized!')
查詢總是返回一個空的結果集(與「WHERE」 -clause)雖然我我確定我已經通過了正確的參數。
我試着連接我自己的查詢字符串,但結果保持不變。如果我刪除了「WHERE」條款,我得到了數據庫的所有用戶,所以我猜數據庫連接沒問題。
我希望你不要在數據存儲中以明文存儲用戶密碼。 –
借調。如果可能,您應該使用聯合登錄或Google帳戶身份驗證。如果您必須存儲用戶憑據,請對用戶的密碼進行散列處理。 –
不要只是散列它 - 使用像PBKDF2這樣的方法。僅靠散佈是不夠的。 –