#NEWLINE# @ classmethod #NEWLINE# def generate_code( cls , length = 20 ) : #NEWLINE# #INDENT# hash_algorithm = getattr ( settings , 'NOPASSWORD_HASH_ALGORITHM' , 'sha256' ) #NEWLINE# m = getattr ( hashlib , hash_algorithm ) ( ) #NEWLINE# m . update ( getattr ( settings , 'SECRET_KEY' , None ) . encode ( 'utf-8' ) ) #NEWLINE# m . update ( os . urandom ( 16 ) ) #NEWLINE# if getattr ( settings , 'NOPASSWORD_NUMERIC_CODES' , False ) : #NEWLINE# #INDENT# hashed = str ( int ( m . hexdigest ( ) , 16 ) ) [ ( - length ) : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hashed = m . hexdigest ( ) [ : length ] #NEWLINE# #UNINDENT# return m