Advertisement
barbos01

onlinebanking

Jun 21st, 2022
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. import hashlib
  2. import json
  3.  
  4.  
  5. class Utilizator:
  6.  
  7.     def __init__(self):
  8.         super().__init__()
  9.         self.email_utilizator = None
  10.  
  11.     def inregistrare(self):
  12.         email = input("Introduceti adresa de email: ")
  13.         confirmare = False
  14.         while not confirmare:
  15.             parola = input("Introduceti parola: ")
  16.             parola_confirmare = input("Confirmati parola: ")
  17.             if parola != parola_confirmare:
  18.                 print("Cele doua parole nu coincid!")
  19.             else:
  20.                 confirmare = True
  21.         enc = parola.encode()
  22.         hash1 = hashlib.md5(enc).hexdigest()
  23.  
  24.         client = email + parola
  25.         client_enc = client.encode()
  26.         client_hash = hashlib.md5(client_enc).hexdigest()
  27.         json_object = {str(client_hash):[{"email": email, "password": hash1}]}
  28.  
  29.         inputfile = open('credentials.json')
  30.         json_object_loaded = json.load(inputfile)
  31.         if client_hash in json_object_loaded:
  32.             print("Acest cont exista!")
  33.             return
  34.  
  35.         dict_final = {**json_object_loaded, **json_object}
  36.         with open("credentials.json", "w") as outfile:
  37.             outfile.write(json.dumps(dict_final))
  38.         outfile.close()
  39.         print("Te-ai inregistrat cu succes!")
  40.  
  41.     def conectare(self):
  42.         email = input("Introduceti adresa de email: ")
  43.         parola = input("Introduceti parola: ")
  44.  
  45.         client = email + parola
  46.         client_enc = client.encode()
  47.         client_hash = hashlib.md5(client_enc).hexdigest()
  48.  
  49.         inputfile = open('credentials.json')
  50.         json_object_loaded = json.load(inputfile)
  51.         if client_hash in json_object_loaded:
  52.             print("Te-ai conectat cu succes!")
  53.             self.email_utilizator = email
  54.             return True
  55.         else:
  56.             print("Datele sunt incorecte!")
  57.  
  58.  
  59.  
  60. def cardValidate(number) :
  61.     lenght = len(number)
  62.     digits = [int(x) for x in str(number)]
  63.     print(digits)
  64.     for el in range(1, lenght, 2):
  65.         digits[el] *= 2
  66.         if digits[el] >= 9:
  67.             digits[el] = int(digits[el] % 10 + (digits[el] / 10) % 10)
  68.     print(digits)
  69.     digits_sum = 0
  70.     for i in range(lenght - 1):
  71.         digits_sum += digits[i]
  72.  
  73.     print(digits_sum)
  74.  
  75.     prod_check = digits_sum * 9
  76.     if prod_check % 10 == digits[lenght - 1]:
  77.         print("Cardul e valid")
  78.  
  79.  
  80. if __name__ == '__main__':
  81.     aplicatie = Utilizator()
  82.     while 1:
  83.         print("********** Online Banking **********")
  84.         print("1.Inregistrare")
  85.         print("2.Conectare")
  86.         print("3.Exit")
  87.         ch = int(input("Alegerea dumneavoastra: "))
  88.         if ch == 1:
  89.             aplicatie.inregistrare()
  90.         elif ch == 2:
  91.             conectare = aplicatie.conectare()
  92.             if conectare:
  93.                 break
  94.         elif ch == 3:
  95.             break
  96.         else:
  97.             print("Wrong Choice!")
  98.  
  99.     while conectare:
  100.         print("********** Alege furnizorii ********** Utilizator: ", aplicatie.email_utilizator)
  101.         inputfile = open('furnizori.json')
  102.         json_object_loaded = json.load(inputfile)
  103.         print(json_object_loaded)
  104.         for key, value in json_object_loaded.items():
  105.             print(value)
  106.         card = input("Introduceti numarul cardului")
  107.         cardValidate(str(card))
  108.         conectare = False
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement