MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / password_generator

Function password_generator

other/password.py:6–22  ·  view source on GitHub ↗

Password Generator allows you to generate a random password of length N. >>> len(password_generator()) 8 >>> len(password_generator(length=16)) 16 >>> len(password_generator(257)) 257 >>> len(password_generator(length=0)) 0 >>> len(password_generator(-1))

(length: int = 8)

Source from the content-addressed store, hash-verified

4
5
6def password_generator(length: int = 8) -> str:
7 """
8 Password Generator allows you to generate a random password of length N.
9
10 >>> len(password_generator())
11 8
12 >>> len(password_generator(length=16))
13 16
14 >>> len(password_generator(257))
15 257
16 >>> len(password_generator(length=0))
17 0
18 >>> len(password_generator(-1))
19 0
20 """
21 chars = ascii_letters + digits + punctuation
22 return "".join(secrets.choice(chars) for _ in range(length))
23
24
25# ALTERNATIVE METHODS

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected