-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential.py
98 lines (71 loc) · 2.79 KB
/
credential.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import pyperclip
import string
import random
class Credential:
"""
class that generates new instances of user credentials
"""
def __init__(self, profile_name, display_profiles = None, profile_username = None, profile_email = None, profile_password = True):
self.profile_name = profile_name
self.profile_username = profile_username
self.profile_email = profile_email
self.profile_password = profile_password
self.display_profiles = display_profiles
profile_list = []
def save_profile(self):
"""
save_profile method saves user object into profile_list
"""
Credential.profile_list.append(self)
@classmethod
def check_profile_exist(cls, profile_name, profile_username = None, profile_email = None):
"""
check_profile_exist method checks if there is another matching or similar profile
Args:
profile to search if it exists
Returns:
Boolean: True or false depending if the profile exists
"""
for profile in cls.profile_list:
if (profile.profile_name == profile_name) or (profile.profile_username == profile_username) or (profile.profile_email == profile_email):
return True
else:
return False
@classmethod
def search_profile(cls, param):
"""
search_profile method that searches for profile/s based on profile name, username or profile_email
Args:
profile to search if it exists
"""
for profile in cls.profile_list:
while (profile.profile_name == param) or (profile.profile_username == param) or (profile.profile_email == param):
return profile
def delete_profile(self):
"""
delete_profile method that deletes a particular profile
"""
Credential.profile_list.remove(self)
@classmethod
def display_all_profiles(cls):
'''
method that returns the all the profiles
'''
return cls.profile_list
@classmethod
def copy_credentials(cls, item):
"""
copy_credentials method that copies a credential to the clipboard
"""
profile_found = cls.search_profile(item)
pyperclip.copy(profile_found.profile_password)
@classmethod
def generate_random_password(cls, length):
"""
generate_random_password method that returns a randomly generated password
Args:
length: The actual length of the password that is to be generated
"""
chars = string.ascii_lowercase + string.ascii_uppercase + string.digits
generated_password = ''.join(random.choice(chars) for char in range(length))
return generated_password