-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordlock.py
102 lines (90 loc) · 3.12 KB
/
passwordlock.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
95
96
97
98
99
100
101
102
import random
import string
import pyperclip
class User:
"""
Create User class that generates new instances of a user.
"""
user_list = []
def __init__(self, username, password):
"""
method that defines the properties of a user.
"""
self.username = username
self.password = password
def save_user(self):
"""
A method that saves a new user instace into the user list
"""
return User.user_list.append(self)
@classmethod
def display_user(cls):
return cls.user_list
def delete_user(self):
'''
delete_account method deletes a saved account from the list
'''
return User.user_list.remove(self)
class Credentials():
"""
Create credentials class to help create new objects of credentials
"""
credentials_list = []
@classmethod
def verify_user(cls,username, password):
"""
method to verify whether the user is in our user_list or not
"""
a_user = ""
for user in User.user_list:
if(user.username == username and user.password == password):
a_user == user.username
return a_user
def __init__(self,account,userName, password):
"""
method that defines user credentials to be stored
"""
self.account = account
self.userName = userName
self.password = password
def save_details(self):
"""
method to store a new credential to the credentials list
"""
return Credentials.credentials_list.append(self)
def delete_credentials(self):
"""
delete_credentials method that deletes an account credentials from the credentials_list
"""
return Credentials.credentials_list.remove(self)
@classmethod
def find_credential(cls, account):
"""
Method that takes in a account_name and returns a credential that matches that account_name.
"""
for credential in cls.credentials_list:
if credential.account == account:
return credential
@classmethod
def copy_password(cls,account):
found_credentials = Credentials.find_credential(account)
pyperclip.copy(found_credentials.password)
@classmethod
def if_credential_exist(cls, account):
"""
Method that checks if a credential exists from the credential list and returns true or false depending if the credential exists.
"""
for credential in cls.credentials_list:
if credential.account == account:
return True
return False
@classmethod
def display_credentials(cls):
"""
Method that returns all items in the credentials list
"""
return cls.credentials_list
def generatePassword(self, stringLength = 8):
"""Generate a random password string of letters and digits and special characters"""
password = string.ascii_uppercase + string.ascii_lowercase + string.digits + "~!@#$%^&*"
return ''.join(random.choice(password) for i in range(stringLength))