diff --git a/change_password.py b/change_password.py index f2f213e..6487f39 100644 --- a/change_password.py +++ b/change_password.py @@ -1,6 +1,6 @@ import time from read_file import read_file - +from hasher import hash_password,check_password def gate_x(t_password): # Enter old password to confirm the new password @@ -11,7 +11,7 @@ def gate_x(t_password): entered_password = input('\nEnter The Old Password : ') if entered_password == "Exit": # Return the Exit flag return '-1' - if entered_password == t_password: # Compere if the Entered password = the True password + if check_password(t_password,entered_password): # Compere if the Entered password = the True password wrong_flag = False # Set to false mean the entered password confirmed break @@ -31,7 +31,7 @@ def change_password(ls): flag = gate_x(old_password) # Security flag get the output flag if flag == '0': - new_password = input("\nEnter the new password: ") + new_password = hash_password(input("\nEnter the new password: ")) '''Get the new password''' file_name = ls[0] + '.txt' process_list = read_file(file_name) @@ -43,7 +43,8 @@ def change_password(ls): last_id = int(process_list[len(process_list) - 1][0]) + 1 # get last id and increment it id_file.write( - '{0}\tchange_password\t\t{1}\t{2}\t{3}\n'.format(str(last_id), str(time.ctime()), old_password, str(new_password))) + '{0}\tchange_password\t\t{1}\t{2}\t{3}\n'.format(str(last_id), str(time.ctime()), old_password, new_password)) + # write process id type before after id_file.close() diff --git a/create_account.py b/create_account.py index 77a7543..42f088f 100644 --- a/create_account.py +++ b/create_account.py @@ -1,13 +1,14 @@ import os - - +from utils import clear_terminal +from hasher import hash_password def create_account(ls): # ls is a list of lists of lines in accounts file # ls is the accounts_list - os.system('clear') + + clear_terminal() account_name = input('Enter Your Name (WITHOUT SPACES): ') - account_password = input('Enter Your Password (WITHOUT SPACES): ') + account_password = hash_password(input('Enter Your Password (WITHOUT SPACES): ')) print("Creating Your Account .....") accounts_file = open('Accounts.txt', 'a') @@ -17,7 +18,7 @@ def create_account(ls): else: new_last_id = int(ls[len(ls) - 1][0]) + 1 - line = '{0}\t{1}\t{2}\t0\n'.format(str(new_last_id), account_name, account_password) + line = '{0}\t{1}\t{2}\t0\n'.format(str(new_last_id), account_name, account_password.hex()) accounts_file.write(line) id_file_name = str(new_last_id) + '.txt' @@ -26,4 +27,4 @@ def create_account(ls): print("Your Account Has Been Created And Your Id Is " + str(new_last_id)) id_file.close() accounts_file.close() - ls.append([str(new_last_id), account_name, account_password, '0']) + ls.append([str(new_last_id), account_name, account_password.hex(), '0']) diff --git a/hasher.py b/hasher.py new file mode 100644 index 0000000..f04e9c0 --- /dev/null +++ b/hasher.py @@ -0,0 +1,17 @@ +import hashlib +import os + +#Created hashers for the password cause if i hear password i see hashes and salts + + +#this function takes the password as string and converts it into hash returns it +def hash_password(password): + salt = os.urandom(16) + hash_obj =hashlib.pbkdf2_hmac('sha256',password.encode(),salt,100000) + return salt + hash_obj +#this function takes hashed password from storage in this case we have Accounts.txt and password(converted into hash) from login input or changepassword and returns if the stored password and the input password are equal then returns true or false +def check_password(hashed_password,password): + hashed_password = bytes.fromhex(hashed_password) + salt = hashed_password[:16] + hash_obj = hashlib.pbkdf2_hmac('sha256',password.encode(),salt,100000) + return hashed_password[16:] == hash_obj \ No newline at end of file diff --git a/info.py b/info.py new file mode 100644 index 0000000..5be422b --- /dev/null +++ b/info.py @@ -0,0 +1,3 @@ +def info_display(account): + print("ID: {}\nName: {}\nBalance: {}\n".format(account[0], account[1], account[3])) + input('Please, press Ctrl+C" to go back') \ No newline at end of file diff --git a/login.py b/login.py index 1470c40..eeaf070 100644 --- a/login.py +++ b/login.py @@ -1,17 +1,19 @@ from menu2 import clear_screen, menu2 - +from hasher import check_password def login(acc_list): login_id = input('Please, Enter your info(press "Ctrl+C" to go back) \n>>ID: ') login_password = input('>>Password: ') found = False for account in acc_list: - if account[0] == login_id and account[2] == login_password: - found = True - clear_screen() - menu2(account) - break + if account[0] == login_id: + print(1) + if check_password(account[2], login_password): + found = True + clear_screen() + menu2(account) + break else: continue diff --git a/atm.py b/main.py similarity index 58% rename from atm.py rename to main.py index 1fea72e..a51da43 100644 --- a/atm.py +++ b/main.py @@ -1,5 +1,5 @@ # create Accounts.txt if not exist - +# Changed the name of atm.py to main.py which is how everyone uses the starting file of python, like i dont know which file is the starting file so its hard to check and read the code so make sure to always use the starting file or main file as main.py try: # read the 'Accounts.txt' file # if you try to open non existing file in read mode, this will throw an error @@ -13,6 +13,6 @@ # import modules import menu1 import os - -os.system('clear') +from utils import clear_terminal +clear_terminal() menu1.menu1() # start the program - call menu1() function diff --git a/menu2.py b/menu2.py index a965f15..e2a4213 100644 --- a/menu2.py +++ b/menu2.py @@ -1,13 +1,13 @@ -import os import withdraw import deposit import show_history import change_password - - +from info import info_display +from utils import clear_terminal def clear_screen(): + clear_terminal() # function to clear the output of the screen - os.system('clear') + print() # print blank line after clearing the screen @@ -24,7 +24,13 @@ def menu2(account): clear_screen() if ch == 1: - print("ID: {}\nName: {}\nBalance: {}\n".format(account[0], account[1], account[3])) + clear_screen() + try: + info_display(account) + except KeyboardInterrupt: + clear_screen() + + elif ch == 2: show_history.show_history(account) elif ch == 3: diff --git a/show_history.py b/show_history.py index bcb752c..8664ace 100644 --- a/show_history.py +++ b/show_history.py @@ -1,6 +1,6 @@ import read_file import os - +from utils import clear_terminal """show_history function: shows the processes made to a certain account""" @@ -35,7 +35,7 @@ def show_history(ls): # id_list[line][2:6] process_date # id_list[line][7] before_process # id_list[line][8] after_process - os.system('clear') + clear_terminal() top_line = '\nID\t' + 'Type'.center(len('change_password')) + 'Date and Time'.center(40) + 'before'.center(10) + 'after'.center(15) print(top_line) print('-' * len(top_line)) @@ -61,4 +61,4 @@ def show_history(ls): print('ERROR: Wrong choice') input('\nPress Enter to go back..') - os.system('clear') + clear_terminal() diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..b9ae1af --- /dev/null +++ b/utils.py @@ -0,0 +1,8 @@ +import os +#The teminal in windows doesn't have os.system('clear') so to clear the terminal in windows we have to use os.system(cls) +def clear_terminal(): + if os.name == 'nt': + os.system('cls') + else: + os.system('clear') + \ No newline at end of file