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