Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions change_password.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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()

Expand Down
13 changes: 7 additions & 6 deletions create_account.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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'
Expand All @@ -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'])
17 changes: 17 additions & 0 deletions hasher.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions info.py
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 8 additions & 6 deletions login.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions atm.py → main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
16 changes: 11 additions & 5 deletions menu2.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions show_history.py
Original file line number Diff line number Diff line change
@@ -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"""


Expand Down Expand Up @@ -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))
Expand All @@ -61,4 +61,4 @@ def show_history(ls):
print('ERROR: Wrong choice')

input('\nPress Enter to go back..')
os.system('clear')
clear_terminal()
8 changes: 8 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -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')