├── LICENSE ├── README.md └── account_login_signup.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Dimitar Dimitrov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Account Manager 2 | 3 | - [Login & Signup](#Login-Signup) 4 | 5 | ### Login-Signup 6 | ![valid-sign-up-log-in](https://user-images.githubusercontent.com/112943652/208107927-ba26f83a-9d9d-47a1-bc0c-b092632eb4be.png) 7 | ![invalid-sign-up](https://user-images.githubusercontent.com/112943652/208107958-8c0eb954-911c-4fe4-adbb-930a826ba521.png) 8 | ![invalid-log-in](https://user-images.githubusercontent.com/112943652/208107980-b58176a6-392c-4d4f-90d3-bbfaac85e683.png) 9 | -------------------------------------------------------------------------------- /account_login_signup.py: -------------------------------------------------------------------------------- 1 | # ---- Imports ---- 2 | import re 3 | from colorama import Fore 4 | 5 | 6 | # ---- Regex patterns ---- 7 | password_pattern = r"^([\S+]{6,25})$" 8 | email_pattern = r"^([\w\.\-]{1,20}\@\w{1,7}\.[a-zA-Z]{1,6})$" 9 | username_pattern = r"^(\w{3,15})$" 10 | 11 | 12 | # ---- Dictionaries ---- 13 | accounts = { 14 | "example_password": [ 15 | "example_email", 16 | "example_username" 17 | ] 18 | } 19 | 20 | ssh = { 21 | "example_username": 22 | "example_password" 23 | } 24 | 25 | 26 | # ---- login variables ---- 27 | input_email_or_username = '' 28 | input_password = '' 29 | 30 | 31 | # ---- signup variables ---- 32 | username = '' 33 | email = '' 34 | password = '' 35 | confirm_password = '' 36 | age = 0 37 | 38 | 39 | # ---- ALTS ---- 40 | save_ssh_alts = {"yes", "y", "ye", "yeah", "yeh"} 41 | login_alts = {"login", "log in", "l", "log", "in", "signin", "sign in"} 42 | signup_alts = {"signup", "sign up", "s", "sign", "up", "logup", "log up"} 43 | 44 | 45 | # ---- Login code ---- 46 | class Login: 47 | 48 | def __init__(self, accounts: dict, input_password: str, input_email_or_username: str): 49 | self.accounts = accounts 50 | self.password = input_password 51 | self.email_or_username = input_email_or_username 52 | 53 | def password_validity(self): 54 | if self.password in self.accounts.keys(): 55 | return True 56 | return False 57 | 58 | def valid_email_or_username(self): 59 | if self.email_or_username in self.accounts[self.password]: 60 | return True 61 | return False 62 | 63 | 64 | def valid_login(log): 65 | if log.password_validity(): 66 | if log.valid_email_or_username(): 67 | return True 68 | return False 69 | return False 70 | 71 | 72 | # login = Login(accounts, input_password, input_email_or_username) 73 | # signed_in = valid_login(login) 74 | # ---- Login code ---- 75 | 76 | 77 | ####################### 78 | ####################### 79 | 80 | 81 | # ---- Signup code ---- 82 | class CAPTCHA: 83 | 84 | def __init__(self): 85 | print("Human CAPTCHA test.") 86 | print("Guess the number:") 87 | 88 | def captcha(self): 89 | counter = 0 90 | 91 | for num in range(1, 10 + 1): 92 | number = int(input(f"{num}: ")) 93 | 94 | if number == num: 95 | counter += 1 96 | 97 | if counter == 3: 98 | return True 99 | 100 | return False 101 | 102 | 103 | class Signup: 104 | 105 | def __init__(self, accounts: dict, username: str, email: str, password: str, confirm_password: str, age: int): 106 | self.accounts = accounts 107 | self.username = username 108 | self.email = email 109 | self.password = password 110 | self.confirm_password = confirm_password 111 | self.age = age 112 | 113 | def username_email_password(self): 114 | ''' 115 | This function checks if the username, email and password already exist 116 | ''' 117 | 118 | if self.password not in accounts.keys(): 119 | if self.email not in accounts.values(): 120 | if self.username not in accounts.values(): 121 | return True 122 | return "Username already exists" 123 | return "Email address already exists" 124 | return "Password already exists" 125 | 126 | def password_confirmed(self): 127 | if self.password == self.confirm_password: 128 | return True 129 | return "The password is different from the confirmation password" 130 | 131 | def how_old(self): 132 | if age > 12: 133 | return True 134 | return "You are too young to use this app" 135 | 136 | def human_captcha(self): 137 | captcha = CAPTCHA() 138 | return captcha.captcha() 139 | 140 | 141 | def successful_signup(sign): 142 | if sign.username_email_password() is True: 143 | if sign.password_confirmed() is True: 144 | if sign.how_old() is True: 145 | if sign.human_captcha is True: 146 | return True 147 | return "Failed human captcha" 148 | return sign.how_old() 149 | return sign.password_confirmed() 150 | return sign.username_email_password() 151 | 152 | 153 | # signup = Signup(accounts, username, email, password, confirm_password, age) 154 | # logged_in = successful_signup(signup) 155 | # ---- Signup code ---- 156 | 157 | 158 | def log_in(): 159 | # ---- global login variables ---- 160 | global input_email_or_username 161 | global input_password 162 | 163 | # ---- Flags ---- 164 | go_back = False 165 | 166 | # ---- changing the values ---- 167 | input_email_or_username = input(Fore.GREEN + "Email address or Username: ") 168 | 169 | if input_email_or_username in ssh.keys(): 170 | print(Fore.WHITE + "Password filled by ssh") 171 | input_password = ssh[username] 172 | else: 173 | input_password = input(Fore.GREEN + "Password: ") 174 | 175 | login = Login(accounts, input_password, input_email_or_username) 176 | signed_in = valid_login(login) 177 | 178 | if not signed_in: 179 | print(Fore.YELLOW + "Invalid Email address, Username or Password") 180 | go_back = True 181 | 182 | if not go_back: 183 | print(Fore.WHITE + f"Welcome {accounts[input_password][1]}!") 184 | 185 | 186 | def sign_up(): 187 | # ---- global signup variables ---- 188 | global username 189 | global email 190 | global password 191 | global confirm_password 192 | global age 193 | 194 | # ---- Flags ---- 195 | go_back = False 196 | 197 | # ---- changing values ---- 198 | username = input(Fore.LIGHTGREEN_EX + ''' 199 | Username must be between 3 and 15 characters long. 200 | Cannot include spaces. Can only contain: letters, numbers and underscore '_': ''') 201 | 202 | username_check = re.findall(username_pattern, username) 203 | 204 | while not username_check: 205 | print(Fore.RED + "Invalid username") 206 | username = input(Fore.LIGHTGREEN_EX + ''' 207 | Username must be between 3 and 15 characters long. 208 | Cannot include spaces. Can only contain: letters, numbers and underscore '_': ''') 209 | 210 | username_check = re.findall(username_pattern, username) 211 | 212 | email = input(Fore.LIGHTGREEN_EX + "Email address: ") 213 | 214 | email_check = re.findall(email_pattern, email) 215 | 216 | while not email_check: 217 | print(Fore.RED + "Invalid email address") 218 | email = input(Fore.LIGHTGREEN_EX + "Email address: ") 219 | 220 | email_check = re.findall(email_pattern, email) 221 | 222 | password = input(Fore.LIGHTGREEN_EX + "Password must be between 6 and 25 characters long. Cannot include spaces: ") 223 | 224 | password_check = re.findall(password_pattern, password) 225 | 226 | while not password_check: 227 | print(Fore.RED + "Invalid password") 228 | password = input(Fore.LIGHTGREEN_EX + "Password must be between 6 and 25 characters long. Cannot include spaces: ") 229 | 230 | password_check = re.findall(password_pattern, password) 231 | 232 | confirm_password = input(Fore.LIGHTGREEN_EX + "Confirm password: ") 233 | 234 | while confirm_password != password: 235 | print(Fore.RED + "The password is different from the confirmation password") 236 | confirm_password = input(Fore.LIGHTGREEN_EX + "Confirm password: ") 237 | 238 | age = int(input(Fore.LIGHTGREEN_EX + "How old are you: ")) 239 | 240 | if age < 12: 241 | print(Fore.RED + "You are too young to use this app") 242 | go_back = True 243 | 244 | if not go_back: 245 | signup = Signup(accounts, username, email, password, confirm_password, age) 246 | logged_in = successful_signup(signup) 247 | 248 | if not logged_in: 249 | Fore.RED + logged_in 250 | go_back = True 251 | 252 | if not go_back: 253 | accounts[password] = [email, username] 254 | 255 | save_ssh_password = input(Fore.LIGHTGREEN_EX + "Do you wanna save password in list of password \"yes\", \"no\": ").lower() 256 | 257 | if save_ssh_password in save_ssh_alts: 258 | ssh[username] = password 259 | print(Fore.GREEN + "Saved!") 260 | 261 | print(Fore.YELLOW + "Welcome home!") 262 | 263 | 264 | def login_signup(): 265 | 266 | while True: 267 | login_or_signup = input(Fore.BLUE + "Login or Signup: ").lower() 268 | 269 | if login_or_signup in login_alts: 270 | log_in() 271 | break 272 | 273 | elif login_or_signup in signup_alts: 274 | sign_up() 275 | break 276 | 277 | print(Fore.RED + "An Error Occurred: Invalid command, please try again!") 278 | 279 | 280 | while True: 281 | login_signup() 282 | --------------------------------------------------------------------------------