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. Sign a string using SHA1, then shrink it using url-safe base65 by simon 4 years, 8 months ago
  2. Truncate HTML without breaking tags by olau 4 years ago
  3. Securely Signed S3 Links With Expiration by pjs 4 years, 6 months ago
  4. User groups template tag by davea 1 year, 7 months ago
  5. Controller Class for Views by jovialbard 1 month ago

Comments

(Forgotten your password?)