MCPcopy Create free account
hub / github.com/dbunt1tled/python-fast-api / random_string

Method random_string

src/core/service/hash_service.py:126–153  ·  view source on GitHub ↗
(
        length: int = 16,
        include_uppercase: bool = True,
        include_lowercase: bool = True,
        include_digits: bool = True,
        include_punctuation: bool = False,
        custom_chars: str | None = None,
    )

Source from the content-addressed store, hash-verified

124
125 @staticmethod
126 def random_string(
127 length: int = 16,
128 include_uppercase: bool = True,
129 include_lowercase: bool = True,
130 include_digits: bool = True,
131 include_punctuation: bool = False,
132 custom_chars: str | None = None,
133 ) -> str:
134 if length < 1:
135 raise ValueError("Length must be at least 1")
136
137 if custom_chars:
138 chars = custom_chars
139 else:
140 chars = ""
141 if include_uppercase:
142 chars += string.ascii_uppercase
143 if include_lowercase:
144 chars += string.ascii_lowercase
145 if include_digits:
146 chars += string.digits
147 if include_punctuation:
148 chars += string.punctuation
149
150 if not chars:
151 raise ValueError("No characters selected for random string generation")
152
153 return "".join(secrets.choice(chars) for _ in range(length))

Callers 4

loginMethod · 0.80
signupMethod · 0.80
refreshMethod · 0.80
createMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected