web-key: Base64 Shared Secret for Access Control

1
2
3
4
5
6
7
8
9
class Foo(models.Model):
    secret = models.CharField(max_length=12, blank=True, editable=False)

    def generateSecret(self):
        s = struct.pack('L', random.getrandbits(32))
        s += struct.pack('L', random.getrandbits(32))
        s += struct.pack('L', random.getrandbits(8))
        self.secret = base64.urlsafe_b64encode(s[0:9])
        self.save()

More like this

  1. Truncate HTML without breaking tags by olau 4 years, 11 months ago
  2. Transparently encrypt ORM fields using OpenSSL (via M2Crypto) by ncoghlan 2 years, 9 months ago
  3. Controller Class for Views by jovialbard 1 year ago
  4. Sign a string using SHA1, then shrink it using url-safe base65 by simon 5 years, 7 months ago
  5. FieldsetForm by Ciantic 7 years ago

Comments

(Forgotten your password?)