├── Andrew └── atm.py ├── Dane ├── Better...ish ├── program.py └── working ├── Documentation ├── File IO.py ├── SQLite3.py ├── Simple Python.py └── bank ├── Otakar ├── ATM.py └── bank ├── README.md └── SQL Program Files ├── SQLite3.py └── bank.db /Andrew/atm.py: -------------------------------------------------------------------------------- 1 | #!user/bin/python3 2 | 3 | import sys, random, os, hashlib, binascii 4 | 5 | # Hashing function 6 | def sha256hash(card, pin, salt_for_card, salt_for_pin): 7 | card_number = str(card) 8 | pin_number = str(pin) 9 | salt_for_card = str(salt_for_card) 10 | salt_for_pin = str(salt_for_pin) 11 | 12 | # Salting card and pin numbers 13 | 14 | salted_card_number = salt_for_card + card_number 15 | salted_pin_number = salt_for_pin + pin_number 16 | 17 | # Unhashing salted card and pin numbers 18 | 19 | sha256_card_number = hashlib.sha256(salted_card_number.encode()).hexdigest() 20 | sha256_pin_number = hashlib.sha256(salted_pin_number.encode()).hexdigest() 21 | 22 | # Return the numbers 23 | 24 | return sha256_card_number, sha256_pin_number 25 | 26 | # Authorization Search 27 | def search_account_security(auth_search): 28 | if os.path.isfile("accountsecurity.txt"): 29 | with open("accountsecurity.txt", "r") as accountsecurity: 30 | for line in accountsecurity: 31 | if auth_search in line: 32 | security = line 33 | auth_bool = True 34 | return security, auth_bool 35 | accountsecurity.close() 36 | # Error 37 | print("Error 2: Card number and pin number not found for user. Please try again.") 38 | sys.exit() 39 | else: 40 | print("Error 8: Accountsecurity.txt not found. Please create an account.") 41 | sys.exit() 42 | 43 | # Authorization Function 44 | def auth(): 45 | 46 | auth_bool = False 47 | 48 | # Getting account name 49 | name = input("What account name do you wish to access?\n> ") 50 | 51 | if os.path.isfile("accountinfo.txt"): 52 | if user_check(name) is True: 53 | print("Error 6: Account not recognized. Please try again.\n") 54 | sys.exit() 55 | else: 56 | print("Error 7: Accountinfo.txt not found. Please create an account") 57 | sys.exit() 58 | 59 | # Checking if name is in account info 60 | # If present, store the line it is on in info 61 | with open("accountinfo.txt", "r") as accountinfo: 62 | for line in accountinfo: 63 | if name in line: 64 | info = line 65 | break 66 | accountinfo.close() 67 | 68 | # Delimit info line by commas 69 | info_array = info.split(",") 70 | 71 | # Gather necessary authorization information 72 | card_number = input("What is your card number?\n> ") 73 | pin_number = input("What is your pin number?\n> ") 74 | salt_for_card = info_array[-2] 75 | salt_for_pin = info_array[-1].replace("\n","") 76 | 77 | # Get hashed authorization information 78 | sha256_card_number, sha256_pin_number = sha256hash(card_number, pin_number, salt_for_card, salt_for_pin) 79 | 80 | # Search for authorization information in accountsecurity.txt 81 | auth_search = sha256_card_number + "," + sha256_pin_number 82 | security, auth_bool = search_account_security(auth_search) 83 | 84 | # Delimit security by commas 85 | security_array = security.split(",") 86 | 87 | original_balance = float(security_array[-1]) 88 | new_balance = float(security_array[-1]) 89 | 90 | return original_balance, new_balance, sha256_card_number, sha256_pin_number, auth_bool 91 | 92 | # Withdrawing money function 93 | def withdraw(balance, amount): 94 | if amount > balance: 95 | print("Error 4: You do not have enough money in your account.\n") 96 | else: 97 | balance -= amount 98 | return balance 99 | 100 | # Deposit money function 101 | def deposit(balance, amount): 102 | balance += amount 103 | return balance 104 | 105 | # Checking balance function 106 | def check_balance(balance): 107 | print("You have " + str(balance) + " dollars.\n") 108 | 109 | # Creating new account function 110 | def create_account(name): 111 | 112 | # Check if user already exists 113 | if os.path.isfile("accountinfo.txt"): 114 | if user_check(name) is True: 115 | account_name = name 116 | else: 117 | # Error 118 | print("Error 1: That username has been taken. Please pick a different username.\n") 119 | sys.exit() 120 | else: 121 | account_name = name 122 | 123 | # Generate random card numbers and pin numbers 124 | card_number = random.randrange(99999999999, 999999999999) 125 | pin_number = random.randrange(999, 9999) 126 | 127 | # Generate random card salts and pin salts 128 | random_hex_card = binascii.b2a_hex(os.urandom(12)) 129 | random_hex_pin = binascii.b2a_hex(os.urandom(12)) 130 | salt_for_card = str(random_hex_card).replace("'","").replace("b","") 131 | salt_for_pin = str(random_hex_pin).replace("'","").replace("b","") 132 | 133 | # Store the account name and salts in accountinfo.txt 134 | with open("accountinfo.txt", "a") as accountinfo: 135 | accountinfo.write(account_name + "," + salt_for_card + "," + salt_for_pin + "\n") 136 | accountinfo.close() 137 | 138 | # Generate hashed card and pin numbers 139 | sha256_card_number, sha256_pin_number = sha256hash(card_number, pin_number, salt_for_card, salt_for_pin) 140 | 141 | # Store hashed card and pin numbers in accountsecuirty.txt 142 | with open("accountsecurity.txt", "a") as accountsecurity: 143 | accountsecurity.write(str(sha256_card_number) + "," + str(sha256_pin_number) + ",0.0\n") 144 | accountsecurity.close() 145 | 146 | # Tell user information 147 | print("Please write down the follow information.\n") 148 | print("Your card number is " + str(card_number) + "\n") 149 | print("Your pin is " + str(pin_number) + "\n") 150 | 151 | # Save function 152 | def save(original_balance, new_balance, sha256_card_number, sha256_pin_number): 153 | 154 | # Replace old data with new data in account security.txt 155 | with open("accountsecurity.txt","r") as accountsecurity: 156 | old_account_security = accountsecurity.read() 157 | old_user_data = sha256_card_number + "," + sha256_pin_number + "," + str(original_balance) + "\n" 158 | new_user_data = sha256_card_number + "," + sha256_pin_number + "," + str(new_balance) + "\n" 159 | new_account_security = old_account_security.replace(old_user_data, new_user_data) 160 | accountsecurity.close() 161 | 162 | with open("accountsecurity.txt","w") as accountsecurity: 163 | accountsecurity.write(new_account_security) 164 | accountsecurity.close() 165 | 166 | # User check function 167 | def user_check(name): 168 | # If username does not exist in accountinfo.txt 169 | # Return True 170 | with open("accountinfo.txt") as usercheck: 171 | for line in usercheck: 172 | if name in line: 173 | return False 174 | usercheck.close() 175 | return True 176 | 177 | def outer_menu(): 178 | # First menu choice 179 | choice = input("Please enter '1' to authenticate.\nPlease enter '2' to open a new acccount.\nPlease enter '3' to exit.\n> ") 180 | 181 | # First Menu 182 | if choice is '1': 183 | original_balance, new_balance, sha256_card_number, sha256_pin_number, auth_bool = auth() 184 | inner_menu(original_balance, new_balance, sha256_card_number, sha256_pin_number) 185 | elif choice is '2': 186 | name = input("Please enter a unique username.\n> ") 187 | 188 | if "," in name: 189 | print("Error 5: Invald character. Please try again.") 190 | sys.exit() 191 | 192 | create_account(name) 193 | elif choice is '3': 194 | print("Thank you for using SST Test Bank. Please have a nice day.\n> ") 195 | sys.exit() 196 | else: 197 | print("Error 3: Invalid choice. Please try again.\n> ") 198 | 199 | def inner_menu(original_bal, new_bal, sha256_card_num, sha256_pin_num): 200 | # Transfering over needed variables 201 | original_balance = float(original_bal) 202 | new_balance = float(new_bal) 203 | sha256_card_number = sha256_card_num 204 | sha256_pin_number = sha256_pin_num 205 | while True: 206 | # Second menu choice 207 | choice = input("Please enter '1' to deposit.\nPlease enter '2' to withdraw.\nPlease enter '3' to check balance.\nPlease enter '4' to save.\nPlease enter '5' to exit.\n> ") 208 | 209 | # Second menu 210 | if choice is '1': 211 | amount = float(input("How much would you like to deposit?\n> ")) 212 | new_balance = deposit(new_balance, amount) 213 | elif choice is '2': 214 | amount = float(input("How much would you like to withdraw?\n> ")) 215 | new_balance = withdraw(new_balance, amount) 216 | elif choice is '3': 217 | check_balance(new_balance) 218 | elif choice is '4': 219 | save(original_balance, new_balance, sha256_card_number, sha256_pin_number) 220 | elif choice is '5': 221 | break 222 | else: 223 | print("Error 3: Invalid choice. Please try again.\n") 224 | 225 | def main(): 226 | print("***Welcome to the SST Test Bank***") 227 | while True: 228 | outer_menu() 229 | 230 | main() 231 | -------------------------------------------------------------------------------- /Dane/Better...ish: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | nusername = '' 4 | susername = '' 5 | 6 | 7 | signed_in = 0 8 | 9 | while signed_in is 0: 10 | nors = input('\nCreate an account (1)\nor\nSign in (2)\n') 11 | if nors is '1': 12 | nusername = input('\nPlease enter your id\n') 13 | file = open(str(nusername) + '.txt', 'w') 14 | fw = open('id', 'a') 15 | fw.write(nusername + '\n') 16 | fw.close() 17 | print('\nRestarting\n') 18 | sys.exit() 19 | elif nors is '2': 20 | susername = input('\nPlease sign in\n') 21 | if susername in open('id').read(): 22 | signed_in = 1 23 | if '0'or'1'or'2'or'3'or'4'or'5'or'6'or'7'or'8'or'9' in open(susername + '.txt').read(): 24 | suserbal = open(susername + '.txt').read() 25 | else: 26 | nullf = open(susername + ',txt', 'w') 27 | nullf.write('0') 28 | nullf.close() 29 | suserbal = 0 30 | else: 31 | print('\nSorry, please try again\n') 32 | else: 33 | print('\nInvalid input\n') 34 | 35 | 36 | def checkbal(): 37 | chkf = open(str(susername) + '.txt', 'r') 38 | print(chkf.read()) 39 | chkf.close() 40 | 41 | 42 | def withdraw(amnt): 43 | witf = open(str(susername) + '.txt', 'r') 44 | witbal = int(witf.read()) 45 | witf.close() 46 | if witbal >= amnt: 47 | witbal -= amnt 48 | wihf = open(str(susername) + '.txt', 'w') 49 | wihf.write(str(witbal)) 50 | wihf.close() 51 | print(witbal) 52 | else: 53 | print('HAHAHAHA you don\'t have that much money! Get a job, you useless swine!') 54 | 55 | def deposit(amnt): 56 | depf = open(str(susername) + '.txt', 'r') 57 | depbal = int(depf.read()) 58 | depf.close() 59 | depbal += amnt 60 | print(depbal) 61 | depf = open(str(susername) + '.txt', 'w') 62 | depf.write(str(depbal)) 63 | depf.close 64 | return depbal 65 | 66 | 67 | while signed_in is 1: 68 | opt = input('\n - Options - \n1 to check your balance\n2 to withdraw\n3 to deposit\n4 to exit\n') 69 | if opt is '1': 70 | checkbal() 71 | elif opt is '2': 72 | wquant = int(input('\nHow much would you like to withdraw?\n')) 73 | withdraw(wquant) 74 | elif opt is '3': 75 | dquant = int(input('\nHow much would you like to deposit?\n')) 76 | deposit(dquant) 77 | elif opt is '4': 78 | signed_in = 0 79 | else: 80 | print('\nInvalid input\n') 81 | -------------------------------------------------------------------------------- /Dane/program.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | bal = 0 4 | 5 | def checkbal(): 6 | return(bal) 7 | 8 | def withdraw(amnt): 9 | x = bal 10 | if amnt < x: 11 | x -= amnt 12 | print(x) 13 | return(x) 14 | else: 15 | print('You can\'t do that!') 16 | 17 | def deposit(amnt): 18 | x = bal 19 | x += amnt 20 | print(x) 21 | return(x) 22 | 23 | while True: 24 | user_input = input('What would you like to do?\nPress 1 to check your balance\nPress 2 to withdraw\nPress 3 to deposit\nPress 4 to exit the program\n') 25 | if user_input is 1: 26 | print(checkbal()) 27 | elif user_input is 2: 28 | user_input2 = input('How much would you like to withdraw?\n') 29 | bal = withdraw(user_input2) 30 | elif user_input is 3: 31 | user_input3 = input('How much would you like to deposit?\n') 32 | bal = deposit(user_input3) 33 | elif user_input is 4: 34 | sys.exit() 35 | else: 36 | print('Invalid input') -------------------------------------------------------------------------------- /Dane/working: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | 5 | nusername = '' 6 | susername = '' 7 | 8 | 9 | signed_in = 0 10 | 11 | while signed_in is 0: 12 | nors = input('\nCreate an account (1)\nor\nSign in (2)\n') 13 | if nors is '1': 14 | nusername = input('\nPlease enter your id\n') 15 | file = open(str(nusername) + '.txt', 'w') 16 | fw = open('id', 'a') 17 | fw.write(nusername + '\n') 18 | fw.close() 19 | print('\nRestarting\n') 20 | sys.exit() 21 | elif nors is '2': 22 | susername = input('\nPlease sign in\n') 23 | if susername in open('id').read(): 24 | signed_in = 1 25 | if os.path.getsize(susername + '.txt') > 0: 26 | suserbal = open(susername + '.txt').read() 27 | else: 28 | nullf = open(susername + '.txt', 'w') 29 | nullf.write('0') 30 | nullf.close() 31 | suserbal = 0 32 | else: 33 | print('\nSorry, please try again\n') 34 | else: 35 | print('\nInvalid input\n') 36 | 37 | 38 | def checkbal(): 39 | chkf = open(str(susername) + '.txt', 'r') 40 | print(chkf.read()) 41 | chkf.close() 42 | 43 | 44 | def withdraw(amnt): 45 | witf = open(str(susername) + '.txt', 'r') 46 | witbal = int(witf.read()) 47 | witf.close() 48 | if witbal >= amnt: 49 | witbal -= amnt 50 | wihf = open(str(susername) + '.txt', 'w') 51 | wihf.write(str(witbal)) 52 | wihf.close() 53 | print(witbal) 54 | else: 55 | print('HAHAHAHA you don\'t have that much money! Get a job, you useless swine!') 56 | 57 | def deposit(amnt): 58 | depf = open(str(susername) + '.txt', 'r') 59 | depbal = int(depf.read()) 60 | depf.close() 61 | depbal += amnt 62 | print(depbal) 63 | depf = open(str(susername) + '.txt', 'w') 64 | depf.write(str(depbal)) 65 | depf.close 66 | return depbal 67 | 68 | 69 | while signed_in is 1: 70 | opt = input('\n - Options - \n1 to check your balance\n2 to withdraw\n3 to deposit\n4 to exit\n') 71 | if opt is '1': 72 | checkbal() 73 | elif opt is '2': 74 | wquant = int(input('\nHow much would you like to withdraw?\n')) 75 | withdraw(wquant) 76 | elif opt is '3': 77 | dquant = int(input('\nHow much would you like to deposit?\n')) 78 | deposit(dquant) 79 | elif opt is '4': 80 | signed_in = 0 81 | else: 82 | print('\nInvalid input\n') 83 | -------------------------------------------------------------------------------- /Documentation/File IO.py: -------------------------------------------------------------------------------- 1 | # Imports 2 | import csv 3 | import os.path 4 | 5 | # Setting file path 6 | directory = os.path.dirname(os.path.abspath(__file__)) 7 | filename = os.path.join(directory, 'bank') 8 | 9 | # Read the csv 10 | with open(filename, 'r') as f: 11 | next(f) # Skips first line because they are headers 12 | reader = csv.reader(f) 13 | for row in reader: 14 | row = list(map(float, row)) 15 | print row # check to see if everything is working thusfar 16 | if 12345 == int(row[0]): 17 | usernameExists = 1 18 | else: 19 | usernameExists = 0 -------------------------------------------------------------------------------- /Documentation/SQLite3.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import sys 3 | conn = sqlite3.connect('bank.db') 4 | c = conn.cursor() 5 | 6 | def checkCard(): 7 | cardNumber = (int(input("Enter account number: ")),) 8 | c.execute("SELECT Number, PIN FROM account WHERE Number = ?", cardNumber) 9 | row = c.fetchall() 10 | if row != []: 11 | raw = row[0] 12 | raw1 = int(raw[1]) 13 | k = 1 14 | pin = (int(input("Please enter your four digit pin: "))) 15 | while k < 5: 16 | if pin == raw1: 17 | print ('CORRECT!') 18 | return 1 19 | else: 20 | pin = int(input("Incorrect, please try again: ")) 21 | k += 1 22 | print("Access Denied!") 23 | sys.exit() 24 | else: 25 | print("This card does not exist, please try again.") 26 | return 0 # Possible add create new account in the future 27 | 28 | checkCard() 29 | 30 | #create_table() 31 | #data_entry() 32 | 33 | -------------------------------------------------------------------------------- /Documentation/Simple Python.py: -------------------------------------------------------------------------------- 1 | # Single line comments start with a hash 2 | # The print function prints out a string 3 | 4 | print ("test") 5 | 6 | # Numbers can be 7 | print (3 + 4) # added 8 | print (3 - 4) # subtracted 9 | print (3 * 4) # multiplied 10 | print (3 ** 4) # power 11 | print (3 / 4) # divided 12 | print (3 // 4) # divided but rounded down 13 | print (3 % 4) # used to find the remainder (modulus) 14 | # Follows order of operation 15 | 16 | # Numbers can be stored in strings 17 | test = 3 18 | print (test + 4) 19 | 20 | # Strings are stored in quotes (single or double) 21 | test = "test" # Strings can be stored in variables 22 | test = 'test' 23 | 24 | donot = 'don\'t' # You can use a backslash to treat the next symbol as normal text 25 | print (r'C:\nudes') # You can add an r to disregard the formatting for the whole string (useful with file paths) 26 | 27 | # You can use math operators on strings 28 | print (test + donot) # This would print out testdon't 29 | print (test * 5) # This would print out testtesttesttesttest 30 | 31 | # You can find a character within a string using an array 32 | test = "TestString" 33 | print (test[0]) # This would print 'T' as arrays start counting from 0 34 | print (test[-2]) # You can start from the back using negative values. This would print out the 'n'. 35 | 36 | # You can print out a certain part of a string using a colon and two numbers. This prints out 'es'. 37 | # From test[1] to test[3] without printing test[3] 38 | print (test[1:3]) 39 | 40 | # Including a blank value means it will start from the beginning/end 41 | print (test[:3]) # Tes 42 | print (test[3:]) # tString 43 | print (test[:]) # TestString 44 | 45 | # The length function finds the length of a string 46 | print(len('test')) # 4 47 | 48 | # You can store many of the same data type in one variable using a list/array 49 | test = [20, 21, 24, 27] 50 | 51 | # You can extract a certain value out of the list using the same technique above 52 | print (test[2]) # 24 53 | print (test[1:3]) # [21, 24] 54 | 55 | # You can append to the list using .append() 56 | test.append(120) 57 | print (test) # [20, 21, 24, 27] 58 | 59 | # You can also just set parts of the list equal to something else 60 | test[1:3] = [0, 0, 0, 0, 0] 61 | print (test) # [20, 0, 0, 0, 0, 0, 27, 120] 62 | test[:] = [] 63 | print (test) # [] 64 | 65 | # A simple function is the if elif else combo 66 | test = 4 67 | 68 | if test < 3: # The if keyword starts out the if elif else combo. Make sure you have a colon after the condition. 69 | print("test is less than 3") # This executes if the if statement is true 70 | elif test is 4: # The is keyword is similar to ==. It tests if something is equal to another thing. elif is optional. 71 | print ("test is 4") 72 | elif test is 3: # You can have no elif, or many elif statements 73 | print ("test is 3") 74 | else: # Else is a catchall statement. If no above statements are true, print the else. The else statement is optional. 75 | print ("test is above 4") 76 | # Make sure your indentations are correct. Indentation shows nesting. 77 | 78 | test = [21, 33, 35, 26] 79 | 80 | # For loops can loop through a list. Assign a random variable (k in this case). 81 | for k in test: # k will be a placeholder for each item 82 | # The first time it loops, k = 21. Then k = 33. etc... 83 | print k # The result is the whole list being printed. 84 | 85 | # You can also loop through only a certain part of the list 86 | for k in test[1:3]: 87 | print k # The result is 33 and 35 88 | 89 | # You can use for loops in conjunction with range 90 | for k in range(10): 91 | print k # This would print 0 through 9 92 | 93 | # This is useful for running code many times 94 | for k in range(10): 95 | print "Andrew is awesome!" # This statement would print 10 times. 96 | 97 | # There are three arguments for the range function 98 | print(range(10)) # With 1 argument, it is just printing x numbers starting from 0. In this case, [0-9] 99 | print(range(3, 10)) # With 2 arguments, it is printing within the stated range. In this case, [3-9] 100 | print(range(3, 10, 2)) # With 3 arguments, it is stepping within the stated range. 101 | # In the above, it will step by 2s from #3 to 9. The output will be [3, 5, 7, 9] 102 | 103 | # The while loop is much simpler. It runs the code while the condition is still true. 104 | test = 0 105 | 106 | while test < 4: # While test is less than 4 107 | print(test) # Print test 108 | test += 1 # And increment test by 1. += -= *= /= %= all do the operation, then set the variable to the outcome 109 | # Note you increment the variable test, in this case, in order to avoid an infinite loop. 110 | 111 | # We can use 'break' to improve the efficiency of our loops. Break simply breaks out of the loop. 112 | test = 34 113 | 114 | for n in range(1000): # We loop 1000 times 115 | if n is test: # If we find that test is equal to n 116 | print(n, "is test") # We print n 117 | break # Now that we know the value of test, we don't need to run the loop anymore. 118 | # We break out of the loop to improve efficiency. 119 | 120 | # Fun fact! In order to print out an integer along with a string, use a comma not a plus sign. 121 | ''' (Triple quotes are a way to multi-line comment) 122 | print(test + "test") # This would error 123 | ''' 124 | print (test, "test") # This would not error 125 | 126 | # 'Continue' is like break, except it doesn't completely break out of the loop. 127 | test = [2, 5, 8, 10] 128 | 129 | for n in range(1, 11): # We set up a loop going from 1 to 10 130 | if n in test: # If the number n is in the test list 131 | continue # Continue, meaning skip all other statements in the loop (print in this case) 132 | # Then continue with the loop for the next n 133 | print(n) # Print n 134 | 135 | 136 | # This code would print out all numbers from 1 to 10 that are not contained in the test list. 137 | # 1, 3, 4, 6, 7, 9 138 | 139 | # Functions are a great way of reusing code without having to rewrite the code every time. 140 | 141 | def testfunction(): # You must first define the function you want 142 | print("This is a test function.") # Then you tell what the function does 143 | print("Pretty cool right?") 144 | 145 | 146 | testfunction() # You can call the function by simply writing its name. 147 | 148 | 149 | # Functions can also take extra information, or arguments 150 | def bitcoin_to_usd(bitcoin): # Put the argument needed in the parentheses, in this case 'bitcoin' 151 | usd = bitcoin * 607.18 152 | print(usd) 153 | 154 | 155 | bitcoin_to_usd(3) # You can call the function the same way as the last time. Just remember to include the argument. 156 | 157 | 158 | # Returning values is more flexible than printing values 159 | def bitcoin_to_usd(bitcoin): 160 | usd = bitcoin * 607.18 161 | return usd # Instead of printing USD, we now return USD. 162 | 163 | 164 | test = bitcoin_to_usd(3.14) # This allows us to do many things like setting the return value equal to another variable 165 | print (test, "USD") 166 | 167 | 168 | # Having a default value for arguments prevents the program from erroring when no argument is given. 169 | def bitcoin_to_usd(bitcoin=0): # We set bitcoin by default to 0. 170 | usd = bitcoin * 607.18 171 | return usd 172 | 173 | 174 | test = bitcoin_to_usd() # If we call this function without entering an argument 175 | print (test, "USD") # The program no longer errors, but rather gives us an output of 0. 176 | 177 | 178 | # There are two basic rules about variables. 179 | 180 | def variable1(): 181 | print(test) 182 | 183 | 184 | test = 1 185 | 186 | variable1() # The variable a function calls must be above the function in order to work. 187 | # Test is defined before we called the function, so this code is not error. 188 | 189 | # This would error as test was not defined before the variable1 function was called: 190 | ''' 191 | def variable1(): 192 | print(test) 193 | 194 | variable1() 195 | 196 | test = 1 197 | ''' 198 | 199 | # Rule two, a variable declared in a function is a local variable. It cannot be utilized outside of that function. 200 | # This would error as test is defined in variable1, so it cannot be used in variable2. 201 | ''' 202 | def variable1(): 203 | test = 1 204 | print(test) 205 | 206 | 207 | def variable2(): 208 | print(test) 209 | ''' 210 | 211 | 212 | # You can have many arguments in a function. 213 | def sentencify(noun="Andrew", verb="is", adjective="awesome"): 214 | print(noun, verb, adjective) 215 | 216 | sentencify() # Since we have default arguments, this does not error. 217 | sentencify("Nobody", "likes", "Otakar") # We can also input our own arguments, 218 | sentencify(noun="Life", adjective="meaningless") # If you want to pass only a few arguments, you need to use keywords. 219 | sentencify(noun="Nobody") # Here is another example 220 | # The keywords are the name of the arguments. In this case: noun, verb, and adjective. 221 | 222 | # If there is an unknown amount of arguments, you can use *args. 223 | 224 | 225 | def addition(*args): # '*args' packs all arguments into a list named args. 226 | total = 0 227 | for n in args: # We add up all the numbers in args 228 | total += n 229 | return total 230 | 231 | total = addition(1, 4, 65, 7, 34, 5, 67, 7) # We can now use as many arguments as we please. 232 | print(total) 233 | 234 | # You can unpack as well as pack arguments 235 | 236 | 237 | def sentencify(noun="Andrew", verb="is", adjective="awesome"): 238 | print(noun, verb, adjective) 239 | 240 | sentence1 = ["Life", "Is", "Unfair"] 241 | 242 | sentencify(sentence1[0], sentence1[1], sentence1[2]) # The normal method is tedious 243 | sentencify(*sentence1) # We can unpack the arguments and do the same thing much quicker by adding an asterisk -------------------------------------------------------------------------------- /Documentation/bank: -------------------------------------------------------------------------------- 1 | CARDNUMBER,PIN,BALANCE 2 | 12345,1234,100.67 3 | 11111,1111,111.01 4 | 10001,1000,1.99 5 | 24442,3829,1999.50 6 | -------------------------------------------------------------------------------- /Otakar/ATM.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # ATM.py 4 | # SST CTF's ATM program that will allows users to modify / view their balances 5 | # Copyright 2016 SST CTF 6 | # 7 | 8 | # Initial Imports 9 | import sys 10 | import csv 11 | import os.path 12 | import time 13 | from random import randint 14 | 15 | # Other setup 16 | directory = os.path.dirname(os.path.abspath(__file__)) 17 | filename = os.path.join(directory, 'bank') 18 | pin = 0 19 | 20 | # Checks if given card number / pin is within database 21 | def checkCard(cardNumber): 22 | with open(filename, 'r') as f: 23 | next(f) # Skips first line because they are headers 24 | reader = csv.reader(f) 25 | userRow = 0 26 | for row in reader: 27 | row = list(map(float, row)) 28 | userRow = userRow + 1 29 | #print row 30 | if cardNumber == int(row[0]): 31 | k = 1 32 | pin = int(input("Please enter your four digit pin: ")) 33 | while k < 5: 34 | if pin == int(row[1]): 35 | #print(userRow) 36 | return (userRow, pin) 37 | else: 38 | pin = int(input("Incorrect, please try again: ")) 39 | k = k + 1 40 | print("Access Denied!") 41 | sys.exit() 42 | print("This card does not exist, please try again.") 43 | createAccount(cardNumber, ) 44 | 45 | # Create account function 46 | def createAccount(cardNumber, pin): 47 | text = (str(cardNumber) + "," + str(pin) + ",0\n") 48 | with open(filename, 'a') as appendFile: 49 | appendFile.write(text) 50 | 51 | # Balance overwite function 52 | def replaceBalance(userRow, cardNumber, pin, balance): 53 | lines = open(filename, 'r').readlines() 54 | text = (str(cardNumber) + "," + str(pin) + "," + str(balance)+ "\n") 55 | lines[userRow] = text 56 | out = open(filename, 'w') 57 | out.writelines(lines) 58 | out.close() 59 | 60 | # Check Balance function 61 | def checkBalance(cardNumber, userRow): 62 | with open(filename, 'r') as f: 63 | next(f) # Skips first line because they are headers 64 | reader = csv.reader(f) 65 | k = 0 66 | for row in reader: 67 | k = k + 1 68 | if k == userRow: 69 | balance = row[2] 70 | return balance 71 | print("ERROR 1: BALANCE READ ERROR") 72 | sys.exit() 73 | 74 | # Deposit function 75 | def deposit(cardNumber, userRow, balance): 76 | depositValue = float(input("How much do you want to deposit? ")) 77 | balance = float(balance) + depositValue 78 | print("Your new balance is $%s" % str(balance)) 79 | replaceBalance(userRow, cardNumber, pin, balance) 80 | return balance 81 | 82 | 83 | # Withdraw function 84 | def withdrawal(cardNumber, userRow, balance): 85 | withdrawalValue = float(input("How much money do you wish to withdraw? ")) 86 | if float(balance) - withdrawalValue >= 0: 87 | balance = float(balance) - float(withdrawalValue) 88 | print("Withdrawal successful.") 89 | print("Your new balance is: $%s" %balance) 90 | replaceBalance(userRow, cardNumber, pin, balance) 91 | return balance 92 | else: 93 | print("ERROR 2: Not enough money to withdraw.") 94 | return float(balance) 95 | 96 | # Clear console when needed 97 | def cls(): 98 | os.system('cls' if os.name=='nt' else 'clear') 99 | 100 | # Program Begins (main menu and GUI) 101 | cls() 102 | print ("**********************************************") 103 | print ("*********** Welcome to the SST ATM ***********") 104 | print ("**********************************************") 105 | userRow = 0 106 | while userRow == 0: 107 | cardNumber = input("Enter your credit card number, '1' to exit, or '0' to create a new account: \n") 108 | if cardNumber == 1: 109 | sys.exit() 110 | elif cardNumber == 0: 111 | cardNumber = input("To create an account please enter a FIVE DIGIT card number: ") 112 | pin = randint(1001,9999) 113 | print("Your pin is: %s" % pin) 114 | createAccount(cardNumber, pin) 115 | userRow, pin = (checkCard(cardNumber)) 116 | else: 117 | userRow, pin = (checkCard(cardNumber)) 118 | balance = checkBalance(cardNumber,userRow) 119 | 120 | # Selection is made here, each selection leads to a function above 121 | selection = 0 # Define initially to run through loop 122 | while selection < 4: 123 | selection = input("\nWhat would you like to do today?:\n 1. Check balance\n 2. Deposit Money\n 3. Withdraw Money\n 4. Exit\n\n") 124 | if selection is 1: # Check Balance 125 | print("Your balance is: $%s" % balance) 126 | elif selection is 2: # Deposit 127 | balance = deposit(cardNumber, userRow, balance) 128 | elif selection is 3: #Withdraw 129 | balance = withdrawal(cardNumber, userRow, balance) 130 | elif selection is 4: # Exit program 131 | print("Thank you, and have a nice day!") 132 | sys.exit() 133 | 134 | # <> Credits <> 135 | # Otakar A. - Primary Developer 136 | # Andrew Q. - Withdraw Function 137 | # Stan L. - Deposit Function 138 | # Tamir E. - Initial Check Balance Function 139 | # 140 | # EOF -------------------------------------------------------------------------------- /Otakar/bank: -------------------------------------------------------------------------------- 1 | CARDNUMBER,PIN,BALANCE 2 | 11111,1111,68.14 3 | 10001,1000,1.99 4 | 24442,3829,1999.50 5 | 44444,3577,20.77 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SST ATM 2 | This is an ATM program that is currently being developed. The purpose of this program is to give everyone on the team a good introduction of python. The ultimate goal is to have an automated text file system and associated Python program to manage balances of many people. 3 | 4 | ## Features 5 | - [x] Deposit 6 | - [x] Withdraw 7 | - [x] View Balance 8 | - [x] Check card number and pin against bank database 9 | - [x] Save withdraw / deposit into database 10 | - [ ] Compound intrest over time 11 | - [x] Open new account 12 | - [x] Encryption TYPE: __ 13 | - [ ] Add any other features here 14 | -------------------------------------------------------------------------------- /SQL Program Files/SQLite3.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import sys 3 | import hashlib 4 | import random 5 | import uuid 6 | 7 | conn = sqlite3.connect('bank.db') 8 | c = conn.cursor() 9 | 10 | def createAccount(): 11 | counter = 1 12 | while counter == 1: 13 | cardNumber = (random.randrange(10000,99999)) 14 | c.execute("SELECT Number FROM Account WHERE NUMBER = ?",(cardNumber,)) 15 | check = c.fetchall() 16 | if check == []: 17 | counter = 0 18 | c.execute('INSERT INTO Account VALUES (?,0,0,0)',(cardNumber,)) 19 | pinchange(cardNumber) 20 | else: 21 | counter = 1 22 | 23 | 24 | def checkBalance(cardNumber): 25 | c.execute("SELECT balance FROM account WHERE Number = ?", (cardNumber,)) 26 | new_balance = c.fetchall() 27 | new_balance1 = new_balance[0] 28 | new_balance2 = new_balance1[0] 29 | print('your balance is: ' + str(new_balance2)) 30 | 31 | def deposit(cardNumber): 32 | deposit_value = float(input("How much do you want to deposit? ")) 33 | c.execute("SELECT Balance FROM Account WHERE Number = ?", (cardNumber,)) 34 | new_balance = list(c.fetchall()) 35 | new_balance = ''.join(str(e) for e in new_balance) 36 | new_balance = float(new_balance[1:-2]) 37 | new_balance += deposit_value 38 | c.execute('UPDATE Account SET Balance = ? WHERE Number = ?', (new_balance, cardNumber)) 39 | conn.commit() 40 | print("Your new balance is " + str(new_balance)) 41 | 42 | def withdraw(cardNumber): 43 | deposit_value = float(input("How much do you want to withdraw? ")) 44 | c.execute("SELECT Balance FROM Account WHERE Number = ?", (cardNumber,)) 45 | new_balance = list(c.fetchall()) 46 | new_balance = ''.join(str(e) for e in new_balance) 47 | new_balance = float(new_balance[1:-2]) 48 | if new_balance > deposit_value: 49 | new_balance -= deposit_value 50 | c.execute('UPDATE Account SET Balance = ? WHERE Number = ?', (new_balance, cardNumber)) 51 | conn.commit() 52 | print("Your new balance is " + str(new_balance)) 53 | else: 54 | print("Error: Not enough balance.") 55 | 56 | def pinchange(cardNumber): 57 | pin_counter = 0 58 | while pin_counter == 0: 59 | new_pin = int(input("Enter new PIN code ")) 60 | check_pin = int(input("Enter PIN code once more ")) 61 | if new_pin == check_pin and len(str(new_pin)) == 4: 62 | salt = uuid.uuid4().hex 63 | c.execute("SELECT salt FROM Account WHERE Number = ?", (cardNumber,)) 64 | c.execute('UPDATE Account SET Salt = ? WHERE Number = ?', (salt, cardNumber)) 65 | new_pin = str(new_pin) 66 | new_pin = hashlib.sha256(new_pin.encode() + salt.encode()).hexdigest() 67 | c.execute("SELECT PIN FROM Account WHERE Number = ?", (cardNumber,)) 68 | c.execute('UPDATE Account SET PIN = ? WHERE Number = ?', (new_pin, cardNumber)) 69 | conn.commit() 70 | print("PIN updated") 71 | pin_counter = 1 72 | print("Your account number is: " + str(cardNumber)) 73 | else: 74 | print("Please try again") 75 | 76 | def checkCard(cardNumber): 77 | c.execute("SELECT Number, PIN FROM account WHERE Number = ?", (cardNumber,)) 78 | row = c.fetchall() 79 | if row != []: 80 | raw = row[0] 81 | raw1 = str(raw[1]) 82 | k = 1 83 | c.execute("SELECT Salt FROM account WHERE Number = ?", (cardNumber,)) 84 | salt = c.fetchall() 85 | salt = salt[0] 86 | salt = salt[0] 87 | while k < 5: 88 | pin = str(input("Please enter your four digit pin: ")) 89 | pin = hashlib.sha256(pin.encode() + salt.encode()).hexdigest() 90 | if pin == raw1: 91 | print ('CORRECT!') 92 | return 1 93 | else: 94 | k += 1 95 | print("Access Denied!") 96 | sys.exit() 97 | else: 98 | print("This card does not exist, please try again.") 99 | return 0 100 | 101 | # Program Begins (main menu and GUI) 102 | print("**********************************************\n*********** Welcome to the SST ATM ***********\n**********************************************") 103 | cardExists = 0 104 | while cardExists == 0: 105 | cardNumber = input("Please enter your credit card number or '2' to create a new account or '1' to exit: ") 106 | if int(cardNumber) == 1: 107 | sys.exit() 108 | elif int(cardNumber) == 2: 109 | createAccount() 110 | else: 111 | cardExists = checkCard(cardNumber) 112 | 113 | # Selection is made here, each selection leads to a function above 114 | selection = 0 # Define initially to run through loop 115 | while int(selection) < 5: 116 | selection = input("What would you like to do today?:\n 1. Check balance\n 2. Deposit Money\n 3. Withdraw Money\n 4. Change PIN number\n 5. Exit\n") 117 | if int(selection) == 1: # Check Balance 118 | checkBalance(cardNumber) 119 | elif int(selection) == 2: # Deposit 120 | deposit(cardNumber) 121 | elif int(selection) == 3: # Withdraw 122 | withdraw(cardNumber) 123 | elif int(selection) == 4: # Change 124 | pinchange(cardNumber) 125 | elif int(selection) == 5: # Exit program 126 | print("Thank you, and have a nice day!") 127 | 128 | c.close() 129 | conn.close() 130 | sys.exit() 131 | -------------------------------------------------------------------------------- /SQL Program Files/bank.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SST-CTF/ATM/b9ca1f477105a01374acb8932cde0fa2e75be877/SQL Program Files/bank.db --------------------------------------------------------------------------------