Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
Minimal max_length of a Django CharField to store the output of the sign method of a Signer object (django.core.signing)

I have to sign a value, in my case emails, and I have to store the signed value in a Django CharField. I am using the Signer.sign method of the django.core.signing module. Since I would like to insert also the max_length parameter for the db field, my question is, what would be the minimal value I can put in the max_length in order to always successfully store it in the db.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

In fact the signing token length grows with the input value:

>>> from django.core.signing import Signer
>>> signer = Signer()
>>> signer.sign('a')
'a:JRYbTbX2xBKZAgJxbzUzsl80vIQ'

>>> signer.sign('ab')
'ab:ThbCyQ9bQpAX4vMAmYSEtbtF7Y4'

>>> signer.sign('abc')
'abc:4_rTdYDe18bPklTTKYIsJaB9_oM'

>>> signer.sign('abcd')
'abcd:RzGFLsNgRv-LQ4lEorvNPjGH5LM'

>>> signer.sign('abcde')
'abcde:oOdfJjZ14Jz2F4aHD3pQMBC9fAA'

>>> signer.sign('abcdefghijkl')
'abcdefghijkl:Wz1gPy4QS7ZoCyXuKgUFG-ofxpU'

However, according to my testing, the maximum size of the token is 27. According to this answer What is the maximum length of a valid email address? maximum length of an email address is 254 characters. max_length attribute of your TextField should be 282 (254+27+1 for separator).

over 4 years ago · Santiago Trujillo Relatório

0

this is what they have given on the Django docs.

from django.core.signing import Signer
>>> signer = Signer()
>>> value = signer.sign('My string')
>>> value
'My string:GdMGD6HNQ_qdgxYP8yBZAdAIV1w'

the sign string is of length of 28 (including ':') plus the length of your email string.to be on the safe side I would suggest you to use Django TextField instead of CharField

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda