wip
This commit is contained in:
11
id.saladeaula.digital/app/security.py
Normal file
11
id.saladeaula.digital/app/security.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import secrets
|
||||
|
||||
SALT_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||
|
||||
|
||||
def gen_salt(length: int) -> str:
|
||||
"""Generate a random string of SALT_CHARS with specified ``length``."""
|
||||
if length <= 0:
|
||||
raise ValueError('Salt length must be at least 1.')
|
||||
|
||||
return ''.join(secrets.choice(SALT_CHARS) for _ in range(length))
|
||||
Reference in New Issue
Block a user