Zdalne-systemy-z-kit-uVPN/utils.py

24 lines
554 B
Python
Raw Normal View History

2023-04-13 09:52:51 +00:00
import hashlib
import secrets
2023-04-13 11:12:08 +00:00
import string
import random
2023-04-14 08:41:07 +00:00
import os
2023-04-13 11:12:08 +00:00
def generate_random_string(length):
2023-04-13 11:23:54 +00:00
letters = string.ascii_letters
2023-04-13 11:12:08 +00:00
random_string = ''.join(random.choice(letters) for i in range(length))
return random_string
2023-04-13 09:52:51 +00:00
def hash_password(password):
return hashlib.sha512(password.encode('utf-8')).hexdigest()
def generate_auth_token():
2023-04-14 08:41:07 +00:00
return secrets.token_urlsafe(32)
def ping_client(ip):
2023-04-14 09:57:27 +00:00
response = os.system("ping -c 1 " + ip + "> /dev/null")
2023-04-14 08:41:07 +00:00
if response == 0:
return True
else:
return False