Open slavos1 opened 2 years ago
A nice example in Python doc -- works on Linux (Ubuntu):
# On standard Linux systems, use a convenient dictionary file.
# Other platforms may need to provide their own word-list.
with open('/usr/share/dict/words') as f:
words = [word.strip() for word in f]
password = ' '.join(choice(words) for i in range(4))
In case the file does not exist, we can fallback to something like:
import string
alphabet = string.ascii_letters + string.digits
password = ''.join(choice(alphabet) for i in range(8))
Or it can just be always random text of some hard-coded length, say:
@pytest.fixture
def description():
alphabet = string.ascii_letters + string.digits
return ' '.join(''.join(choice(alphabet) for _ in range(num_chars)) for _ in range(num_words))
We use it only for generating a simple sentence; can use alphanums sequence chosen by secrets.choice instead.