I’m creating a small app using python 2.7 with google app engine and I’m trying to store a hash similar to…
import hashlib
def PassHash(self):
return hashlib.sha256(
hashlib.sha256(self.username).digest() + self.password
).hexdigest() + ''
This returns a string of hexadecimal which I then try to store in a class like this:
class User(db.Model):
UserName = db.StringProperty()
Password = db.StringProperty(multiline = True)
Email = db.EmailProperty()
def Authenticate(self):
UserList = User.gql("WHERE UserName = :username and Password = :password",
username = self.UserName,
password = self.PassHash())
return UserList.count() == 1
def Register(self):
self.Password = self.PassHash()
print self.Password
return db.put(self)
This worked for the first few test cases, but after that I got this exception:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 28: character maps to <undefined>
I suspect the problem may lie in the gql query, possibly. I’ve considered just using openid, but this would be useful to know how to do in general. I’ve tried several different variations of the hash function with no luck. Am I missing something about what can be stored in a StringProperty() property?
I would try without the multiline attribute for the password. I could store sha hashed variables like the following: