2011-11-07 85 views
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」條款,我得到了數據庫的所有用戶,所以我猜數據庫連接沒問題。

+1

我希望你不要在數據存儲中以明文存儲用戶密碼。 –

+0

借調。如果可能,您應該使用聯合登錄或Google帳戶身份驗證。如果您必須存儲用戶憑據,請對用戶的密碼進行散列處理。 –

+0

不要只是散列它 - 使用像PBKDF2這樣的方法。僅靠散佈是不夠的。 –

回答

3

這可能是因爲您在字段上使用了TextPropertyTextProperty適用於多行文本並且未編入索引。您無法在查詢中查找非索引值。您應該使用StringProperty作爲單行文本值。

+0

確實如此。我不知道谷歌數據存儲就這樣工作。非常感謝你。它解決了這個問題,今天我學到了一些新的東西:-) – Frederik