def default_keymaker(self, user): ''' Default keymaker. Creates key based on random salt and email ''' key = random_string(string.digits + string.ascii_letters, 10) key = key + user.email sha = hashlib.sha1() sha.update(key) key = sha.hexdigest() return key
def default_keymaker(self, user): """ Default keymaker. Creates key based on random salt and email """ key = random_string(string.digits + string.ascii_letters, 10) key = key + user.email sha = hashlib.sha1() sha.update(key) key = sha.hexdigest() return key
def _gen_unique_auth_secret(self): ''' Generate a globally-unique authentication secret This ensures that this auth_secret is unique, so it can be used later on to locate the UID during a pairing. ''' #another good technique for this is to create a hash of #'sitesecret:uid' sec = random_string(self.auth_chars, self.auth_length) while self.filter(auth_secret=sec): sec = self.random_string(self.auth_chars, self.auth_length) return sec
def pair_phone(self, auth_secret): ''' Pairs a user's phone to the database Will update the user's auth_secret with a randomly-generated string that should be sent by the client on each following request. If successful, will mark the user's paired flag. Returns the newly paired user. raises PairingException ''' try: u = self.get_by_auth_secret(auth_secret) if u.paired: raise PairingException('User has already paired') u.auth_secret = random_string(self.auth_key_chars, self.auth_key_length) u.paired = True u.save() return u except self.model.DoesNotExist, e: raise PairingException('User not found for given auth_secret')