def _get_new_session_key(self): "Returns session key that isn't being used." # Todo: move to 0-9a-z charset in 1.5 hex_chars = '1234567890abcdef' # session_key should not be case sensitive because some backends # can store it on case insensitive file systems. while True: session_key = get_random_string(32, hex_chars) if not self.exists(session_key): break return session_key
def make_random_password(self, length=10, allowed_chars='abcdefghjkmnpqrstuvwxyz' 'ABCDEFGHJKLMNPQRSTUVWXYZ' '23456789'): """ Generates a random password with the given length and given allowed_chars. Note that the default value of allowed_chars does not have "I" or "O" or letters and digits that look similar -- just to avoid confusion. """ return get_random_string(length, allowed_chars)
def handle(self, project_name=None, target=None, *args, **options): if project_name is None: raise CommandError("you must provide a project name") # Check that the project_name cannot be imported. try: import_module(project_name) except ImportError: pass else: raise CommandError("%r conflicts with the name of an existing " "Python module and cannot be used as a " "project name. Please try another name." % project_name) # Create a random SECRET_KEY hash to put it in the main settings. chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' options['secret_key'] = get_random_string(50, chars) super(Command, self).handle('project', project_name, target, **options)
def _get_new_csrf_key(): return get_random_string(CSRF_KEY_LENGTH)
def salt(self): return get_random_string(2)
def salt(self): """ Generates a cryptographically secure nonce salt in ascii """ return get_random_string()