You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB
Python

import re
import pwd
def checkUsernameCharacters(username: str):
if re.match("[a-z]+[a-z0-9]", username):
return True
else:
return False
def checkUsernameLength(username: str):
if len(username) > 16:
return False
if len(username) < 3:
return False
return True
def checkUserExists(username: str):
try:
pwd.getpwnam(username)
except KeyError:
return True # User already exists
else:
return False # User doesnt exist
def checkSSHKey(key: str):
# taken from https://github.com/hashbang/provisor/blob/master/provisor/utils.py, all belongs to them! ;)
import base64
if len(key) > 8192 or len(key) < 80:
return False
key = key.replace("\"", "").replace("'", "").replace("\\\"", "")
key = key.split(' ')
types = ['ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521', 'ssh-rsa', 'ssh-dss', 'ssh-ed25519']
if key[0] not in types:
return False
try:
base64.decodebytes(bytes(key[1], "utf-8"))
except TypeError:
return False
return True
def checkEmail(mail: str):
if not re.match("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", mail):
return False
else:
return True